how do i separate the keys of this dict into two separate lists?
score = {(13.5, 12.0): 10.5, (10.7, 19.3): 11.4, (12.4, 11.1): 5.3}
list1 = []
list2 = []
so that I can have these lists when I print them?
list1 = [13.5, 10.7, 12.4]
list2 = [12.0, 19.3, 11.1]
i’ve tried this but it doesn’t work
for (a, b), x in score:
list1.append(a,)
list2.append(b,)
Your code is almost correct, just remove the
, x.Iterating over a dictionary iterates over its keys, not its keys and values. Since you only need the keys here, iterating over the dictionary is fine.
Alternatively, you could iterate over
score.items()instead (orscore.iteritems()only on Python 2).