Advertisement
here2share

# dict_from_list_comprehension.py

Sep 5th, 2015
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.26 KB | None | 0 0
  1. # dict_from_list_comprehension.py
  2.  
  3. t = [(10, 20), (30, 40), (50, 60)]
  4. print dict(t) # {10: 20, 30: 40, 50: 60}
  5.  
  6. gen = [(i, i+1) for i in range(1, 6, 2)]
  7. print dict(gen) # {1: 2, 3: 4, 5: 6}
  8.  
  9. print {i: i*100 for i in range(1, 4)} # {1: 100, 2: 200, 3: 300}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement