Login and get codingDid we already tell you we love the
collections
module? In this Bite we combine itsdefaultdict
andCounter
data structures for powerful data querying.We will use this cool South Park data set (thanks Peter for the idea and collaboration on this one!). See the template below: we already completed
get_season_csv_file
to load in the csv data for a given season.You need to complete
get_num_words_spoken_by_character_per_episode
which receives the loaded csv data (example) and parse it into a defaultdict of Counter objects (don't forget to split by newlines first). Here is a snippet what you should end up with:{'Agent 1': Counter({'8': 48, '2': 1}), ... # Counter k,v here = (episode, # number of words spoken) ... 'Anthropologist': Counter({'12': 101}), ... 'Cartman': Counter({'1': 735, '10': 669, '13': 621, ... etc ...Why is this cool? This structure makes it easy to do lookups by character, for example: Cartman was most talkative in episode 1, Agent 1 in episode 8, etc. See more checks under the TESTS tab. Ready to add
collections
to your toolkit? Have fun!
268 out of 280 users completed this Bite.
Will you be the 269th person to crack this Bite?
Resolution time: ~79 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 8.0 on a 1-10 difficulty scale.
» Up for a challenge? 💪