Reputation: 67
So, I have a list of items like,
mylist = ['apple', '"banana"', 'orange']
I want to remove double quotes from the item banana in mylist. The resulting list should look like this,
myresultlist = ['apple' , 'banana', 'orange']
I have tried function i.replace('"', "") but no luck. Is it possible?
Upvotes: 1
Views: 56
Reputation: 149
mylist = ['apple', '"banana"', 'orange']
newlist = []
for item in mylist:
newlist.append(item.strip('"'))
print(newlist)
Upvotes: 1
Reputation: 195418
Try str.replace
and list-comprehension:
mylist = ["apple", '"banana"', "orange"]
mylist = [v.replace('"', "") for v in mylist]
print(mylist)
Prints:
['apple', 'banana', 'orange']
Upvotes: 5