t900.py 473 B

123456789101112131415161718192021222324252627282930313233343536
  1. import collections
  2. print collections.defaultdict()
  3. print collections.defaultdict(None)
  4. print collections.defaultdict(None, {})
  5. print collections.defaultdict(None, {1:2})
  6. d = collections.defaultdict(list, {1:2})
  7. print d
  8. print d[1]
  9. print d[2]
  10. d[2].append(5)
  11. print d[2]
  12. print d
  13. print d.default_factory
  14. print d.get(2)
  15. def abc():
  16. return 6
  17. d = collections.defaultdict(abc)
  18. print d
  19. print d[4]
  20. d[4] += 8
  21. print d
  22. print
  23. print
  24. print
  25. x = {1:2, 4:6}
  26. print x
  27. print x.get(4)