I want to convert
E =[1,6,1,7,2,3,2,6,3,2,3,8,4,5,4,7,5,4,5,9,6,1,6,7,6,2,7,1,7,6,7,4,8,9,8,3,9,8,9,5,]
into
E = [{1,6},{1,7},{2,3},{2,6},{3,2},{3,8},{4,5},{4,7},{5,4},{5,9},{6,1},{6,7},{6,2},{7,1},{7,6},{7,4},{8,9},{8,3},{9,8},{9,5}
but I get
E=[[{1, 6}], [{1, 7}], [{2, 3}], [{2, 6}], [{2, 3}], [{8, 3}], [{4, 5}], [{4, 7}], [{4, 5}], [{9, 5}], [{1, 6}], [{6, 7}], [{2, 6}], [{1, 7}], [{6, 7}], [{4, 7}], [{8, 9}], [{8, 3}], [{8, 9}], [{9, 5}]]
instead, and also the order in the sets {.} all get mixed up (order not preserved).
Why is this the case and how can I solve this?
My code is:
def convert_to_set(x):
sets = []
l = len(x)
for i in range(0,l,2):
set1 = []
set1.append({x[i],x[i+1]})
sets.append(set1)
return sets