Alternate soluton is to use python string replacement - and then pass the full query string. Provided you know the dynamically generated comma separated string or can build it.
Python code: query = " select * from students where name in (%s);"
#some for loop which will create below string students_list_str = 'MUSK', 'TRUMP'
query_str = query%(students_list_str) #Now query_str = " select * from students where name in ('MUSK', 'TRUMP');"
cursor.execute(query_str)