Removing all occurences of a character from a string.
Alex Martelli
aleax at aleax.it
Wed Sep 25 05:14:14 EDT 2002
Mike C. Fletcher wrote:
> Under later Python versions (such as 2.2.1), you can do the following:
>
> attr = [[item.replace("'","") for item in element] for element in attr]
>
> Which is rather elegant IMO. It also has the side-effect of _not_
> rewriting the data in-place in your original list, instead just
> replacing that list when we are finished creating the new list, which
> may or may not be desirable for you.
If it's NOT desirable, just assign to attr[:] tather than to attr.
Alex
More information about the Python-list
mailing list