Piotr Pawlicki Piotr Pawlicki - 4 years ago 196
Python Question

comparing 2 list indexes

I have a problem with comparing 2 list indexes.
In code

inventory=['q', 'w', 'e', 'r']

print(inventory)

if 'q' and 'w' in inventory:

a=inventory.index('q')
b=inventory.index('w')
else:
print('\nNothing')
if a > b:
a+=1
del inventory[:a]
print("Your inventory:")
print(inventory)
print(a)
elif b<a:
b+=1
del inventory[:b]
print("Your inventory:")
print(inventory)
print(b)
else:
print('Sth went wrong')
print(a,b)


a
and
b
don't want to compare -output from console is :

['q', 'w', 'e', 'r']
Sth went wrong
0 1

It seams, that 2 ints are unable to compare. Does anybody know why?

Answer Source

In your if statement you have

if a > b:
    ...
elif b < a:
    ...

These are the same thing. The second condition should be b > a:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download