IM Creating list of str. how can remove the " in the list please?
['xxxxx', '', 'bb', "'errrr'"]
output desired:
['xxxxx', '', 'bb', 'errrr']
thank you
IM Creating list of str. how can remove the " in the list please?
['xxxxx', '', 'bb', "'errrr'"]
output desired:
['xxxxx', '', 'bb', 'errrr']
thank you
You can replace()
or strip()
the single quote '
your_list = [s.replace("\'", "") for s in your_list]
your_list = [s.strip("\'", "") for s in your_list]
# e.g
your_list = [s.replace("\'", "") for s in ['xxxxx', '', 'bb', "'errrr'"]]
Double quotes appear in print()
because you have single quotes '
in one of your list elements
Example of the element is on 3rd position : 'errrr'
.
Or if you want to strip double quotes "
as well
your_list = [ s.strip("\'\"") for s in your_list]`
your_list = [ s.strip("\'\"") for s in ['xxxxx', '', '"bb"', "'errrr'"]]
print(your_list)
> ['xxxxx', '', 'bb', 'errrr']
your issue is related to your '
charcter from the string
you may see Using quotation marks inside quotation marks
for your example you can use str.replace method:
l = ['xxxxx', '', 'bb', "'errrr'"]
l[3] = l[3].replace("'", '')
l
output:
['xxxxx', '', 'bb', 'errrr']
or you can use str.strip:
l[3] = l[3].strip("'")