Oct-23-2020, 09:12 PM
I am trying to remove the first item from a list at every iteration if when subtracted from the next number on the list will give a result that is equal or greater than 1.
The following code produces the right outcome but mixed with error messages.
How to fix my code so I get only the answer without the error messages?
The following code produces the right outcome but mixed with error messages.
How to fix my code so I get only the answer without the error messages?
nums = [0,1,3,4,6,8,10] for i in range(len(nums)): if (nums[i]-nums[0] >=1): del(nums[0])
Error:[0, 1, 3, 4, 6, 8, 10]
if (my_list[i]-my_list[0] >=1):
[1, 3, 4, 6, 8, 10]
IndexError: list index out of range
[3, 4, 6, 8, 10]
[4, 6, 8, 10]
Process finished with exit code 1