We can skip value in a list python by applying logic on an iterator. While iterating the list object we can filter multiple values either all are following a certain pattern or we can direct ignore them by lookup their values. In this article, we will explore the best ways for skipping values from the list object.
To skip a value in a list python : ( Methods ) –
We can skip values on the basis of the below points.
1. Skipping values on the basis of the index.
2. Values skipping on the basis of the pattern.
3. Skipping values on the basic value ( direct lookup )
So let’s create a sample list that we will use for filtering.
sample_list=[1,2,3,4,5,6,7]
1. Skipping values on the basis of the index –
Suppose you want to skip the element which is occurring at the 4th index of the list then we can simply use an iterator and skip.
sample_list=[1,2,3,4,5,6,7]
for i in range(len(sample_list)):
if (i !=4):
print(i)

2. Values skipping on the basis of the pattern –
Suppose you want to skip the values which are even numbers then we can simply apply the pattern matching with the if clause.
sample_list=[1,2,3,4,5,6,7]
temp_list=[]
for i in range(len(sample_list)):
if (sample_list[i] %2==0):
print(i)
temp_list.append(sample_list[i])
print("Final List is :")
print(temp_list)

3. Skipping values on the basis value –
Suppose you want to skip a certain value from the list sequence list then in the above loop you need to provide the value which you want to ignore. The rest part you can pass.
sample_list=[1,2,3,4,5,6,7]
temp_list=[]
for i in range(len(sample_list)):
if (sample_list[i] !=6):
temp_list.append(sample_list[i])
print("Final List is :")
print(temp_list)

Here you can see that we have skipped values and created a new list on the basis of new requirements. we can reassign the new list to the original one for a normal run.
Thanks
Data Science Learner Team
Join our list
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.