<p>I have a python list, say l</p>

<pre><code>l = [1,5,8]
</code></pre>

<p>I want to write a sql query to get the data for all the elements of the list, say</p>

<pre><code>select name from students where id = |IN THE LIST l|
</code></pre>

<p>How do I accomplish this?</p>

string.join
the list values separated by commas, and use the
format operator
to form a query string.
```
```
myquery = "select name from studens where id in (%s)" % ",".join(map(str,mylist))
```
```
(Thanks,
blair-conrad
)