some new examples

This commit is contained in:
Mari Wahl 2014-08-25 13:47:59 -04:00
parent 5ed530430c
commit b50dc5d69d
84 changed files with 130 additions and 82 deletions

View file

@ -1,27 +0,0 @@
#!/usr/bin/python3
# mari von steinkirch @2013
# steinkirch at gmail
from collections import defaultdict
def defaultdict_example():
''' show some examples for defaultdicts '''
pairs = {('a', 1), ('b',2), ('c',3)}
d1 = {}
for key, value in pairs:
if key not in d1:
d1[key] = []
d1[key].append(value)
print(d1)
d2 = defaultdict(list)
for key, value in pairs:
d2[key].append(value)
print(d2)
if __name__ == '__main__':
defaultdict_example()