vendredi 16 août 2019

why does my for loop not edit the global list I and looping through and editing?

There is probably a matching question out there. I have a globally defined list and I am trying to iterate through the list and edit certain elements by using specific if statements. My problem is that when I print the list before the loop and when I print the list afterwards they are still the same.

I've considered using enumerate to manually edit list["enumerated number"] using the numbers connected to the element but this seems clumsy.

print(list)
       for el in list:
           print(el)
           if el < 1:
               el = 0
           elif el > 1:
               el = 2
print(list)

I am hoping to get an output that is the top list edited according to the if statements.

Aucun commentaire:

Enregistrer un commentaire