How to create a dictionary containing keys and each key maps to a list of strings in Python

1 Answer

0 votes
mydict = dict(
    one = ['aa', 'bbb', 'cccc', 'ddddd', 'eeeeee'], 
    two = ['fff', 'ggg', 'hhh'], 
    three = ['iiii', 'jjjj'])

print(mydict)
print(mydict['one'])
print(mydict['one'][0])
print(len(mydict['one']))

print()
for i in range(len(mydict['one'])):
    print(mydict['one'][i])

print()  
for lst in mydict.values():
    for i, s in enumerate(lst):
        print(i, s)


'''
run:

{'one': ['aa', 'bbb', 'cccc', 'ddddd', 'eeeeee'], 'two': ['fff', 'ggg', 'hhh'], 'three': ['iiii', 'jjjj']}
['aa', 'bbb', 'cccc', 'ddddd', 'eeeeee']
aa
5

aa
bbb
cccc
ddddd
eeeeee

0 aa
1 bbb
2 cccc
3 ddddd
4 eeeeee
0 fff
1 ggg
2 hhh
0 iiii
1 jjjj

'''

 



answered Mar 24 by avibootz
edited Mar 24 by avibootz
...