python 3.x - Accessing values in a dictionary -
here dictionary:
{'request': [yearcount( year=2005, count=646179 ), yearcount( year=2006, count=677820 ), yearcount( year=2007, count=697645 ), yearcount( year=2008, count=795265 )], 'wandered': [yearcount( year=2005, count=83769 ), yearcount( year=2006, count=87688 ), yearcount( year=2007, count=108634 ), yearcount( year=2008, count=171015 )], 'airport': [yearcount( year=2007, count=175702 ), yearcount( year=2008, count=173294 )]}
i need figuring out how access yearcount - count value. because i'm trying find letter frequency of each word such 'request', 'wandered', , 'airport'. count total number of each letter occurring in words in input data set. number divided total number of letters in words.
if that's dictionary can access list of yearcount
objects doing:
objects = my_dict['request']
you can iterate on list , access .count
values:
for year_count in objects: print(year_count.count)
you can add them total count word:
total = 0 year_count in objects: total += year_count.count print(total)
to display word occurrences can do:
for word, year_counts in my_dict.items(): total = 0 year_count in year_counts: total += year_count.count print(word, total)
Comments
Post a Comment