List of string

sp1d3rx at gmail.com sp1d3rx at gmail.com
Thu Aug 18 12:26:15 EDT 2005


to quote you :
"['0134314244133', '132443', '234']

2nd and 3rd strings are also substrings from the 1st one , so it should
be removed "

Actually, no, the 2nd string does not substring match the first, nor
does the 3rd.  If you are referring to matching individual characters,
then yes, characters 1 2 3 4 are in the first string. In that case you
would want to use the replace() function. Just specify the characters
you want to strip as the first arguement to "replace()".  See the
example below...

>>>x = "this is not a test"
>>>x.replace("t","") #delete the letter t
'his is no a es'
>>> x.replace("not ","")
'this is a test'
>>> x.replace("notas","") # wont work because it treats the first arg as a string, not a list of characters
'this is not a test'




More information about the Python-list mailing list