Guest User

Untitled

a guest
Dec 14th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. [{key1: [val1, val2]}, {key2: [val3, val4]}, {key3: [val5, val6]}, ...]
  2.  
  3. my_list = [3423, 77813, 12, 153, 1899]
  4.  
  5. [{3423:['dog', 'cat']}, {77813:['dog', 'cat']}, {12:['dog', 'cat']},
  6. {153:['dog', 'cat']}, {1899:['dog', 'cat']}]
  7.  
  8. for i in my_list:
  9. d = {} ## create a dictionary 'd'
  10. d[i] = [].append('dog') ## or `d[i] = ['dog'].append('cat')`
  11. my_list.append(d) ## here is a bug
  12. my_list.remove(i) ## remove the item from the list
  13.  
  14. new_list = []
  15. for i in my_list:
  16. d = {}
  17. d[i] = [].append('dog')
  18. new_list.append(d)
  19. my_list.remove(i)
Add Comment
Please, Sign In to add comment