Home > Blockchain >  I have an index of variables. I need to find which ones are linked to a value of 1 and print their l
I have an index of variables. I need to find which ones are linked to a value of 1 and print their l

Time:07-13

Apples = 1
Oranges = 0
Bananas = 1
Grapes = 0

list1 = ["Apples", "Oranges", "Bananas", "Grapes"]

So in this example the locations should be 0 and 2.

CodePudding user response:

Apples = 1
Oranges = 0
Bananas = 1
Grapes = 0

list1 = [Apples, Oranges, Bananas, Grapes]
y = len(list1)

for x in range(0,y):
    if list1[x] == 1:
        print (x)

CodePudding user response:

I'm not sure what you're trying to do, but maybe a Python dictionary will help you. Check this link:

https://www.w3schools.com/python/python_dictionaries.asp

The sidebar on the left side of the page has more links to documentation on everything you can do with dictionaries.

  • Related