Since lists are a mutable, once you remove the first instance of a string from the the list using the 'remove' method, the indexes in the original list, l, shift:
'world' = 0; 1.25 = 1; 5 = 2; 20 = 3; 'hi' = 4
Because the 'for' loop has already iterated over the first index [0] by removing the first string 'hello', it would then move onto index 1 which is the element 1.25 in this example. It would be essentially passing over 'world' since 'world' has an index of 0, and index 0 was already addressed in the previous loop.
I'd recommend sticking with list aliases moving forward, so you don't run into this issue.
My code works in Jupyter notebook; however, I receive the following error when executing in CodeWar's shell:
"ModuleNotFoundError: import of inspect halted; None in sys.modules"
Any idea what is going on?
Your current code works, so, what was the problem importing numpy?
Are you not able to import packages? I attempted to import numpy to treat the directions as coordinates on a plane. I keep receiving an error.
Your program's issue is due to indexing. Let's say your initial list, l, is the following
When Python executes the 'for' loop line of code, it assigns the elements in the list the following indexes:
'hello' = 0; 'world' = 1; 1.25 = 2; 5 = 3; 20 = 4; 'hi' = 5
Since lists are a mutable, once you remove the first instance of a string from the the list using the 'remove' method, the indexes in the original list, l, shift:
'world' = 0; 1.25 = 1; 5 = 2; 20 = 3; 'hi' = 4
Because the 'for' loop has already iterated over the first index [0] by removing the first string 'hello', it would then move onto index 1 which is the element 1.25 in this example. It would be essentially passing over 'world' since 'world' has an index of 0, and index 0 was already addressed in the previous loop.
I'd recommend sticking with list aliases moving forward, so you don't run into this issue.
This comment is hidden because it contains spoiler information about the solution