Python:: how to put double quotes for values in a list
16,320
- strip the
[]
:abc[1:-1]
- split on
,
:.split(',')
- bracket each element with
""
:'"'+x+'"'
- join with
,
:','.join
- add the
[]
:'['+...+']'
TL;DR:
'['+','.join(['"'+x+'"' for x in abc[1:-1].split(',')])+']'
Related videos on Youtube
![bruce_karlo](https://lh3.googleusercontent.com/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/4252rscbv5M/photo.jpg?sz=256)
Author by
bruce_karlo
Updated on September 18, 2022Comments
-
bruce_karlo almost 2 years
In Python Scripting, I have a string abc=[9874,209384,20938]
I want the output as abc=["9874","209384","20938"]
My efforts got me "9874" "209384" "20938"
but I want like this ["9874","209384","20938"]
-
Anaksunaman about 5 yearsabc=['"9874"','"209384"','"20938"'] perhaps? Note that these examples are wrapped in single
' '
quotes (outside) then double" "
quotes (inside).
-