I have a list of rows returned from an excel sheet. I want to use the replace function on each item in row to replace '
with \'
however, this does not work:
row = map(replace('\'', "\\'"), row)
this just gives an error about replace taking at most 3 arguments but only having 2.
is there a way to use replace with map in python?
map( lambda s: s.replace(...), row )
or use a list comprehension
[s.replace(...) for s in row]
The idiomatic Python here is probably to use a list comprehension:
row = [ x.replace('\'', "\\'") for x in row ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With