mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-05-24 01:11:35 -04:00
Change the dir structure slightly
This commit is contained in:
parent
6b6fe21db3
commit
2f4a9638c0
184 changed files with 0 additions and 21 deletions
|
@ -1,27 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
__author__ = "bt3"
|
||||
|
||||
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()
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue