0

Is this correct? How do i fix the error?

for i in range(10):
        for j in range(10):
            if(list[i] != alpha[j])
3
Contributors
3
Replies
4
Views
11 Years
Discussion Span
Last Post by k_en
0

What do you want it to do? What does it do? Error message? Give a little more information.
BTW: Don't call a variable list, this is a keyword in Python ;)

0

Mawe is right! Using Python keywords as variable names in your code can lead to nasty errors. Otherwise your code should work the following way ...

# test

list1 = range(10)
alpha = range(10, 0, -1)

print list1  # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print alpha  # [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

for i in range(10):
        for j in range(10):
            if (list1[i] != alpha[j]):
                print list1[i], alpha[j]  # skips 1,1  2,2  etc.

This adds a temporay print statement to test your code's logic.

0

:mrgreen: Thank You. My Error is using the python keyword list.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.