Removing all occurences of a character from a string.

Sean Ross sross at connectmail.carleton.ca
Wed Sep 25 05:36:01 CEST 2002


Thank you Justin.

How about this, then:

I have a list of lists of these strings and I want to apply replace to each
string in the list of lists.

So, say:

attr = [ ["'gill-attachment'", "'a'", "'d'", "'f'",
"'n'"],["'gill-spacing'", "'c'", "'d'", "'w'"], ["'gill-size'", "'b'",
"'n'"]]

I can do the following:
for i in xrange(0, len(attr)):
    for j in xrange(0,len(attr[i])):
         attr[i][j] = attr[i][j].replace("'","")

to get what I want; which is:
[ ['gill-attachment', 'a', 'd', 'f', 'n'],['gill-spacing', 'c', 'd', 'w'],
['gill-size', 'b', 'n']]

Is there a nicer way to do this?
Sean


"Justin Shaw" <wyojustin at hotmail.com> wrote in message
news:DL9k9.201596$216.7001230 at bin4.nnrp.aus1.giganews.com...
> > How can I remove the single quotes so that "'Hello World'" becomes
"Hello
> World"?
>
> Try this one:
>
> >>> s = "'Hello World'"
> >>> print s.replace("'", "")
> Hello World
> >>>
>
> Justin
>
> > I have a string, say "'Hello World'", where Hello World is in single
> > quotes(i.e., 'Hello World'). How can I remove the single quotes so that
> > "'Hello World'" becomes "Hello World"?
> > Thanks
> > Sean Ross
> >
> >
>
>





More information about the Python-list mailing list