Why this list of dictionaries doesn't work?
Gilcan Machado
gilcanmachado at gmail.com
Thu Jun 18 13:57:01 EDT 2015
Hi,
I'm trying to write a list of dictionaries like:
people = (
{'name':'john', 'age':12} ,
{'name':'kacey', 'age':18}
)
I've thought the code below would do the task.
But it doesn't work.
And if I "print(people)" what I get is not the organize data structure like
above.
Thanks of any help!
[]s
Gilcan
#!/usr/bin/env python
from collections import defaultdict
person = defaultdict(dict)
people = list()
person['name'] = 'jose'
person['age'] = 12
people.append(person)
person['name'] = 'kacey'
person['age'] = 18
people.append(person)
for person in people:
print( person['nome'] )
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150618/8a148e82/attachment.html>
More information about the Python-list
mailing list