Dec-06-2019, 05:11 PM
Hi everyone,
So I am basically trying to iterate over a list of 12 values and if a value at a specific index (every third) is also a value in a dictionary, I want to append that corresponding key to a new list. ps is a list with 12 values. dict is a dictionary also with 12 keys and values.
So I am basically trying to iterate over a list of 12 values and if a value at a specific index (every third) is also a value in a dictionary, I want to append that corresponding key to a new list. ps is a list with 12 values. dict is a dictionary also with 12 keys and values.
ps = [57.06, 98.74, 83.3, 77.24, 63.59, 101.11, 83.2, 90.67, 85.12, 72.28, 86.16, 92.56]
for key, value in dict.items(): for count in range(0,10,3): if value == ps[count]: list1.append(key)So I want to append the keys to the values in list1 at indexes 0,3,6 and 9. This works but they are appended in random order it seems. So when I print the list1 I get values in the oder(6,0,3,9).Does anyone know if there is a way to make sure it gets appended rigth? Any help would be much appreciated.