Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. list1=[1,2,3,4]
  2. list2=["qwe","asd","zxc"]
  3. dictx={}
  4. for x in range(len(list1)):
  5. if x>len(list2):
  6. dictx[list1[x]]=None
  7. else:
  8. dictx[list1[x]]=list2[x]
  9.  
  10. from itertools import chain, repeat
  11.  
  12. d = dict(zip(list1, chain(list2, repeat(None))))
  13.  
  14. import itertools
  15. list1=[1,2,3,4]
  16. list2=["qwe","asd","zxc"]
  17. print ({l1:l2 for l1,l2 in itertools.izip_longest(list1,list2,fillvalue=None)})
  18.  
  19. import itertools
  20. list1=[1,2,3,4]
  21. list2=["qwe","asd","zxc"]
  22. print ({l1:l2 for l1,l2 in itertools.zip_longest(list1,list2,fillvalue=None)})
  23.  
  24. {1: 'qwe', 2: 'asd', 3: 'zxc', 4: None}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement