I have a list:
my_list = [\'\"3\"\', \'\"45\"\',\'\"12\"\',\'\"6\"\']
This list has single and double quotes and the item value. How can I repl
As suggested by @MartijnPieters in comments, you can use replace on the strings to get the desired output.
The change I like to suggest is that using .replace('"', '')
instead of .replace('"', ' ')
. Otherwise the resultant strings will have a leading and trailing white space
You can use list comprehension to deal with the list you have like this
my_list = ['"3"', '"45"','"12"','"6"']
new_list = [x.replace('"', '') for x in my_list]
print(new_list) # ['3', '45', '12', '6']