I have a dictionary in python which looks like this
my_dict = {
'100':[['a', [10], [5]]],
'101':[['a', [10], [7]]],
'102':[['a', [10], [11]]],
'103':[['a', [10], [4]]],
}
To create my_dict,
my_dict = dict()
id_nums = ['100', '101', '102', '103', ...]
for id in id_nums:
info_list = list()
## code to populate info list
# based on certain conditions
if some_condition:
info_list.insert(0, 'a')
info_list.insert(1, list1) # list_1 is passsed from another function
else:
info_list.insert(0, 'a')
info_list.insert(1, [])
if other_condition:
info_list.insert(2, list2) # list2 is being passed from other function
else:
info_list.insert(2, [])
if id not in my_dict.keys():
my_dict[id] = list()
my_dict[id].append(info_list)
Where info list contains ['a', [10], [x].
I'm looping over all the keys in the dict and my goal is to delete number at 1st index in each value i.e. 10. To achieve this I have:
for k in my_dict.keys():
my_dict[k][1].remove(10)
When I execute above code, at the very first key i.e. '100' the remove method also deletes 10 from the values of all the keys in my_dict.
Can anybody help me understand why this happens? and also how it can be avoided?
Thanks