What is the equivalent of python 'in' but for sqlalchemy
<p>I have a dictionary that is being used to query the database for a match. I have one single query line that isn't working for me. If i have a list like this:</p>

<pre><code>user['names']= [Alice, Bob, John]
</code></pre>

<p>Since this is a list I tried to use something like this:</p>

<pre><code> q.filter(UserTable.firstname in user['firstnames'])
</code></pre>

<p>But for whatever reason this doesn't work. However, I know that Bob is in the database. When I manually pull down all the queries I can see the name is there in one of the rows. If I do this instead:</p>

<pre><code>q.filter(UserTable.firstname == user['firstnames'][1]) #Only does Bob
</code></pre>

<p>It works. And when I pull all the queries manually, convert each row to a dictionary, and then do a </p>

<pre><code>row[#row_that_matches].firstname in user['names']
</code></pre>

<p>that also works. But for some reason using the "in" keyword in sqlalchemy doesn't work as expected. Does anyone know an alternative that can make an sqlalchemy query for something in a list of values?</p>

<p>Use the <a href="http://docs.sqlalchemy.org/en/rel_1_0/core/sqlelement.html#sqlalchemy.sql.operators.ColumnOperators.in_" rel="nofollow"><code>in_()</code> column method</a> to test a column against a sequence:</p>

<pre><code>q.filter(UserTable.firstname.in_(user['firstnames'])
</code></pre>

<p>See the <a href="http://docs.sqlalchemy.org/en/rel_1_0/orm/tutorial.html#common-filter-operators" rel="nofollow"><em>Common Filter Operations</em> section</a> of the Object Relational tutorial:</p>

<blockquote>
  <p><code>IN</code>:</p>

<pre><code>query.filter(User.name.in_(['ed', 'wendy', 'jack']))

# works with query objects too:
query.filter(User.name.in_(
        session.query(User.name).filter(User.name.like('%ed%'))
))
</code></pre>
</blockquote>

python mysql list sqlalchemy