Ali Mir
Ali Mir

Reputation: 565

How do I determine if a number in a list exists in a range?

I am looping through a range but every time the i in range is equal to one of the integers in check_list, I should continue and iterate next. Here's my code:

check_list = [23,5,6,3,6,3]
for i in range(1000):
    if i == one of the numbers in check_list:
        continue
    # do something here

Upvotes: 0

Views: 70

Answers (2)

ettanany
ettanany

Reputation: 19806

You need just to use:

if i in check_list:

Take a look at this example:

>>> check_list = [23, 5, 6, 3, 6, 3]
>>> for i in range(10):
...     if i in check_list:
...         print(i)
...
3
5
6

Upvotes: 2

Yevhen Kuzmovych
Yevhen Kuzmovych

Reputation: 12130

Use operator in:

check_list = [23,5,6,3,6,3]
for i in range(1000):
    if i in check_list:
        continue
    # do something here

Upvotes: 3

Related Questions