Reputation: 51
x = ['"yes',
'3',
'""McGowan Miss. Anna """"Annie""""""',
'female#',
'15',
'8.0292"']
for string in x:
for character in string:
character = character.replace('"','')
x
gives
['"yes',
'3',
'""McGowan Miss. Anna """"Annie""""""',
'female#',
'15',
'8.0292"']
and I don't know why its not removing the " from the strings...
Thanks in advance!
EDIT:
how would I iterate through a List of List?
x = [['"yes',
'3',
'""McGowan Miss. Anna """"Annie""""""',
'female#',
'15',
'8.0292"'],[True,
1,
'Futrelle Mrs. Jacques Heath (Lily May Peel)',
'female',
'35',
'53.1']]
with
for i in x:
for b in i:
b[i] = b[i].replace('"', '')
doesnt work...
EDIT2: fixed, my x had integers and booleans
Upvotes: 0
Views: 114
Reputation: 10194
You need to replace the string
, not character
.
x = ['"yes',
'3',
'""McGowan Miss. Anna """"Annie""""""',
'female#',
'15',
'8.0292"']
for i in range(len(x)):
x[i] = x[i].replace('"', '')
print(x)
Upvotes: 1
Reputation: 2441
Replace you whole for loop with this:
for i, string in enumerate(x):
x[i] = string.replace('"','')
Upvotes: 3