Question: I have a function that returns the following:

```
def choose_tables(self):
...
...
return final_table_set

```

Which returns a list of integers that looks like this:

```
[11,12,13,14,15]

```

The problem I am having is I am trying to use that return value in another function that executes SQL and returns it in a DataFrame:

```
def execute_sql(self):
    s = self.connection()
    data = self.choose_tables()
    data2 = "SELECT * FROM TABLE_A WHERE TABLE_ID IN ({})".format(data)
    df = pd.read_sql(data2, s) 

```

it errors out because it reads it like this:

```
'SELECT * FROM TABLE_A WHERE TABLE_ID IN ([11, 12, 14, 15])'

```

Is there a way to get rid of those brackets around the numbers? I am assuming I need to do that in the choose\_tables() function somewhere at the end before I return final\_table\_set? These are integers, not strings for the use in the SQL statement so I don't think ','.join will work

Answer: 
There are [security concerns](https://xkcd.com/327/) associated with constructing SQL strings from variables, but that aside - the easiest way to get the result you're looking for is:

```
data = [11,12,13,14,15]
sql = "SELECT * FROM TABLE_A WHERE TABLE_ID IN ({})".format(",".join(str(d) for d in data))

>>> 'SELECT * FROM TABLE_A WHERE TABLE_ID IN (11,12,13,14,15)'

```
Use map to convert each element in the list to a string, then use join as you hinted in your question:

```
data2 = "SELECT * FROM TABLE_A WHERE TABLE_ID IN ({})".format(','.join(map(str, data)))

```