I'm working on analyzing some user data, and I've got a list of (preprocessed to lowercase) usernames, something like this:
name_list = ['joebob', 'sallycat', 'bigbenny', 'davethepirate', 'nightninja', ...(many more)]
and a dictionary of comparisons I'd like to run on those names to see how often certain words show up compared to certain others. For example...
comparisons = {"Pirates vs Ninjas": ["pirate", "ninja"],
"Cats vs Dogs": ["cat", "dog"]}
I'm trying to get a loop/comprehension with output that would look like
{"Pirates vs Ninjas": {"pirate": 224, "ninja": 342},
"Cats vs Dogs": {"cat": 430, "dog": 391}}
(With the numbers above just being examples of end result word counts)
I know all the individual components necessary to make it work (dictionary comprehensions and dict.get
). What is the right way to put it all together?
Edit for clarification: I want to see how many usernames contain the word "cat", and record that next to a number that contain the word "dog". The results will be logged in a dict with a key "Cats vs Dogs". I would then proceed to do the same with the next comparison, "Pirates vs Ninjas".