Paste Search Dynamic
Recent pastes
MyDefaultDict
  1. import random
  2. from collections import defaultdict
  3.  
  4.  
  5. class MyDefaultDict(defaultdict):
  6.     def __str__(self):
  7.         return f"{{{', '.join(f'{k}: {v}' for k, v in self.items())}}}"
  8.  
  9.  
  10. def print_dict(d: dict):
  11.     print(f"{{{', '.join(f'{k}: {v}' for k, v in d.items())}}}")
  12.  
  13.  
  14. def main():
  15.     ddict = MyDefaultDict(list)
  16.     for i in range(10):
  17.         ddict[random.randrange(3)].append(i)
  18.     print(ddict)
  19.     print_dict(ddict)
  20.  
  21.  
  22. main()
  23.  
Parsed in 0.006 seconds