Skip to content
Advertisement

Last element of list not being taken into account for if statement

I’m an absolute beginner at python and I need to write a code which can differentiate between 2 lists. Overall code works yet, consistently the last element of the list is not being taken into account and lists such as “AT, AC” are being considered the same. I would love some help. Thanks !

JavaScript

Advertisement

Answer

You exit the loop too early which is a common mistake:

JavaScript

There is a built-in shortcut for this pattern (all) which you can combine with zip to make this more concise:

JavaScript

for lists, you can also just check equality:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement