Advertisement
here2share

# dict_functional.py

Sep 7th, 2015
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. # b_dict_functional.py
  2.  
  3. result = {}
  4. def fn(x):
  5.     result.update ({
  6.         'a': x *  5,
  7.         'b': x +  7,
  8.         'c': x -  2,
  9.         5  : x == 5,
  10.         0  : x *  20
  11.         })
  12.        
  13. 0
  14. fn(5)
  15. print result.get('b') # 12
  16. print result.get(0)   # 100
  17. print result.get(5)   # True
  18. print result.get('x') # None
  19. x=100
  20. print result.get(x)   # None
  21. result['z'] = 'Zzz...'
  22. print result # {'a': 25, 0: 100, 'c': 3, 'b': 12, 5: True, 'z': 'Zzz...'}
  23. fn(100)
  24. print result # {'a': 500, 0: 2000, 'c': 98, 'b': 107, 5: False, 'z': 'Zzz...'}
  25. print result.get('z')   # 'Zzz...'
  26. print result['c'] # 98
  27. print result['x'] # KeyError: 'x'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement