I have a question about range in the for statement!

Asked 2 years ago, Updated 2 years ago, 69 views

I just started coding, so I have a question

for j in range(len(list2)):
    for w in range(len(list2[0])):
        if list3[w] != list2[j][w]:
            new_list.append(list2[j][w])

J = 0, 1 w = 0, 1, 2, 3, 4, 5 We know that w = 0, 1, 2, 3, 4, 5 are repeated at j = 0 and then j = 1 to repeat w again.

If len(new_list) > 1 before moving from j=0 to j=1, run new_list.clear() len(new_list) == 1 I want to stop the for door, but I have no idea how to code it!

for range if문

2022-09-20 15:05

1 Answers

for j in range(len(list2)):
    for w in range(len(list2[0])):
        if list3[w] != list2[j][w]:
            new_list.append(list2[j][w])

    if len(new_list) > 1:
        new_list.clear()
    elif len(new_list) == 1:
        break


2022-09-20 15:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.