MedaUser
MedaUser

Reputation: 133

Dictionary accessing keys and values

So my dictionary looks like this:

{'wandered': [YearCount( year=2005, count=83769 ), YearCount( year=2006, count=87688 ), YearCount( year=2007, count=108634 ), YearCount( year=2008, count=171015 )], 'request': [YearCount( year=2005, count=646179 ), YearCount( year=2006, count=677820 ), YearCount( year=2007, count=697645 ), YearCount( year=2008, count=795265 )], 'airport': [YearCount( year=2007, count=175702 ), YearCount( year=2008, count=173294 )]}

The values are held in a YearCount object that holds the year and count.

How do I access each letter in the each key, ex. 'wandered',? I'm trying to create a list containing the relative frequency of letters scaled by the total letter count in alphabetical order.

Ex.

[0.03104758705050717, 0.0, 0.0, 0.03500991824543893, 0.2536276129665047, 0.0, 0.
0, 0.0, 0.013542627927787708, 0.0, 0.0, 0.0, 0.0, 0.017504959122719464, 0.013542
627927787708, 0.013542627927787708, 0.10930884736053291, 0.15389906233882777, 0.
10930884736053291, 0.12285147528832062, 0.10930884736053291, 0.0, 0.017504959122
719464, 0.0, 0.0, 0.0]

Upvotes: 0

Views: 57

Answers (1)

simonzack
simonzack

Reputation: 20928

You can do it like this:

for key in d:
    for letter in key:
        print(key, letter)

Upvotes: 1

Related Questions