I want to be able to find all members of a group and all groups that an item is a member of…
The first part of this seems easily solved using a dict:
groups = {
'Group1': [ 'Member A', 'Member B', 'Member C' ],
'Group2': [ 'Member A', 'Member D', 'Member E' ],
'Group3': [ 'Member C', 'Member E', 'Member F' ]
}
But do I have to iterate through all the Groups to find which one(s) ‘Member C’ is a member of, or is the answer to be found somewhere in the use of sets? What’s the quickest way of doing this?
Second, is there a way to search the entire ‘groups’ dict to find all groups that ‘Member A’ belongs to or am I still stuck with iterating through all of the keys one at a time?
Keep in mind that these are just doing the loop for you, but it might work more the way you’re thinking. The idea is you hand the data to successive filter functions and operations to get a final new data structure with what you want.