I want to assign a value to each tuple in a list. Let's say my list looks like this:
[(68, 125), (113, 69), (65, 86), (108, 149), (152, 53), (78, 90), (54, 160), (20, 137), (107, 90), (48, 12)]
I need to assign each of these tuples into a dict where it should look like:
1 [(48, 12)]
2 [(68, 125), (54, 160), (20, 137)]
3 [(113, 69), (152, 53)]
4 [(108, 149)]
This is what I have so far:
new_dict = {"1":[], "2":[], "3":[], "4":[]}
for (x,y) in numbers:
if (x,y) == (48, 12):
new_dict += {"1:"[(x,y)]}
elif (x,y) == (68, 125) or (x,y) == (54, 160) or (x,y) == (20, 137):
new_dict += {"2:"[(x,y)]}
elif (x,y) == (113, 69) or (x,y) == (152, 53):
new_dict += {"3:"[(x,y)]}
elif (x,y) == (108, 149):
new_dict += {"4:"[(x,y)]}
return new_dict
Help will be much appreciated. Thank you.