I am new to Python so please excuse. I'm running some code that gives the following output-
Michael
John
Jack
Harry
I want to convert the output like
'Michael','John',Jack','Harry'How should I go about doing this.
Thanks for all help.
If the output is a string you can convert it to list using split()
myString = 'Someone, something, somebody'
myList = myString.split(', ')
The newly created myList
will look like this:
['Someone', 'something', 'somebody']
If you have many strings that you want to add to a list you can use append()
myList.append(myString)
Or you can just add them all together:
myList = [myString0, myString1]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.