"how to convert list into string with quotes in python" Code Answer

2

this seems to be the only solution so far that isn't a hack...

>>> mylist = [1,2,3]
>>> ','.join("'{0}'".format(x) for x in mylist)
"'1','2','3'"

this can also be written more compactly as:

>>> ','.join(map("'{0}'".format, mylist))
"'1','2','3'"
By Saqib Ali on August 8 2022
Only authorized users can answer the Search term. Please sign in first, or register a free account.