0

I'm new to Python and I have this code which looks through a list of lists and it changes the values to either 0, 1 or 2 using an if statement. However, it's not changing anything at all. Here's what it looks like:

distance_list = np.array(distances)
for lists in distance_list:
    for i in lists:
        if i < short:
            i = 0
        elif i > short and i < max_drive:
            i = 1
        elif i > max_drive: 
            i = 2

Since it seems to be quite simple, I don't understand why it isn't working, it just returns the same list from the beginning.

Jakub Bláha
  • 1,491
  • 5
  • 22
  • 43
  • 5
    `i` is assigned each value in the list in turn. Assigning something else to `i` doesn't alter the list the value came out of. – khelwood Apr 23 '18 at 18:34
  • Might I recommend `numpy.select` instead, if you're working with numpy arrays – cs95 Apr 23 '18 at 18:37

0 Answers0