Created
April 2, 2014 12:37
-
-
Save kanazux/9933225 to your computer and use it in GitHub Desktop.
Default dict on python collections module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
dicionario = defaultdict(list) | |
fox1982 = {"ano" : "2008", "cor" : "branco", "revisao" : "ok"} | |
fox8219 = {"ano" : "2009", "cor" : "branco", "revisao" : "not ok"} | |
dicionario['carros'].append(fox1982) | |
dicionario['carros'].append(fox8219) | |
for carro in dicionario['carros']: | |
print carro['ano'] | |
#2008 | |
#2009 | |
for carro in dicionario['carros']: | |
print carro | |
#{'ano': '2008', 'revisao': 'ok', 'cor': 'branco'} | |
#{'ano': '2009', 'revisao': 'not ok', 'cor': 'branco'} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment