How to create, initialize and print a list of dictionaries in Python

2 Answers

0 votes
dir_list = [{'c': 'ccc', 'b': 222}, {'d': 'ddd', 'a': 111}]

print(dir_list)


'''
run:

[{'c': 'ccc', 'b': 222}, {'d': 'ddd', 'a': 111}]

'''

 



answered Oct 26, 2017 by avibootz
0 votes
dir_list = [{'c': 'ccc', 'b': 222}, {'d': 'ddd', 'a': 111}]

for i in range(len(dir_list)):
    for keys, values in dir_list[i].items():
        print(keys)
        print(values)


'''
run:

c
ccc
b
222
d
ddd
a
111

'''

 



answered Oct 26, 2017 by avibootz

Related questions

5 answers 1,564 views
1 answer 161 views
1 answer 131 views
1 answer 176 views
4 answers 308 views
...