Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [{key1: [val1, val2]}, {key2: [val3, val4]}, {key3: [val5, val6]}, ...]
- my_list = [3423, 77813, 12, 153, 1899]
- [{3423:['dog', 'cat']}, {77813:['dog', 'cat']}, {12:['dog', 'cat']},
- {153:['dog', 'cat']}, {1899:['dog', 'cat']}]
- for i in my_list:
- d = {} ## create a dictionary 'd'
- d[i] = [].append('dog') ## or `d[i] = ['dog'].append('cat')`
- my_list.append(d) ## here is a bug
- my_list.remove(i) ## remove the item from the list
- new_list = []
- for i in my_list:
- d = {}
- d[i] = [].append('dog')
- new_list.append(d)
- my_list.remove(i)
Add Comment
Please, Sign In to add comment