Check for existence in list : <p>I have a somewhat stupid question which drives me nuts for a couple of days now. Heavy web search did not help either.</p>

<p>Within some larger SQLAlchemy application I want to check whether some value exists inside a list or not (before the SQL is executed). Therefore I have defined two functions: one which checks the existence of a value inside a list, and gives back True or False. Plus a second one which loops as long as the value is not in the list:</p>

<pre><code>def check_value(itemlist, value_check):
    print(itemlist) #only for debugging reasons
    if value_check in itemlist:
        print('Item is already in list') #only for debugging reasons
        return False
    else:
        print('Item is not in list') #only for debugging reasons
        return True

def check_input(itemlist, value_check):
    while check_value(itemlist ,value_check)==False:
        value_check = input('Please input valid value')
    return value_check
</code></pre>

<p>now if I run this code lets say:</p>

<pre><code>def check_value(itemlist, value_check):
    print(itemlist) #only for debugging reasons
    if value_check in itemlist:
        print('Item is already in list') #only for debugging reasons
        return False
    else:
        print('Item is not in list') #only for debugging reasons
        return True

def check_input(itemlist, value_check):
    while check_value(itemlist ,value_check)==False:
        value_check = input('Please input valid value')
    return value_check

if __name__ == "__main__":

        items = [1, 18272, 18279, 12, 298]
        value_check = 18272
        check_input(items, value_check)
</code></pre>

<p>IDLE gives me the correct answer at first:</p>

<pre><code>[1, 18272, 18279, 12, 298]
Item is already in list
Please input valid value
</code></pre>

<p>Then I give it a number that is also in the list let's say "1" but it still tells me the value is not in the list:</p>

<pre><code>[1, 18272, 18279, 12, 298]
Item is not in list
&gt;&gt;&gt; 
</code></pre>

<p>Its clear that this has been asked several times and I have found some help here already:<a href="https://stackoverflow.com/questions/14608015/how-to-check-if-a-specific-integer-is-in-a-list">How to check if a specific integer is in a list</a> I tried this method x is in (see code above).</p>

<p>Also I found this thread: <a href="https://stackoverflow.com/questions/176918/finding-the-index-of-an-item-given-a-list-containing-it-in-python">Finding the index of an item given a list containing it in Python</a> which would be my workaround to check for index of a given value and write some try/except around it. Nevertheless I do not understand why x is y is not working here.</p>

<p>I have the feeling I am missing something very basic here but I am not able to grasp what.</p>
