I'm trying to figure out how to remove specific index from list, but I don't know how to fix my problem. Can someone help me to solve this?
First, I have to get some numbers from users using input.
numbers = int(input("input any numbers: "))
list_num = list(numbers)
Second, if list_num[0] == 1, remove that element.
Third, if list_num[i+1] == list_num[i], remove list_num[i+1].
So, if the initial list goes like this: list_num = [1,2,7,8,13,20,21]
,
the final list will be list_num = [2,7,13,20]
This is the program to be fixed:
numbers = int(input("input any numbers:"))
list_num = list(numbers)
if list_num[0] ==1:
list_num.remove(num[0])
for i in range(1,len(list_num)-1, 1):
if list_num[i] = list_num[i+1] -1:
list_num.remove(num[i+1])
print(list_num)