dict_views.py 410 B

123456789101112131415161718192021
  1. d = {1: 2}
  2. for m in d.items, d.values, d.keys:
  3. print(m())
  4. print(list(m()))
  5. # print a view with more than one item
  6. print({1:1, 2:1}.values())
  7. # unsupported binary op on a dict values view
  8. try:
  9. {1:1}.values() + 1
  10. except TypeError:
  11. print('TypeError')
  12. # unsupported binary op on a dict keys view
  13. try:
  14. {1:1}.keys() + 1
  15. except TypeError:
  16. print('TypeError')
  17. # set operations still to come