List of string

BranoZ zarnovican at gmail.com
Thu Aug 18 12:47:31 EDT 2005


Dennis Lee Bieber wrote:
> On Thu, 18 Aug 2005 13:30:45 +0200, Mohammed Altaj <mohammed at aims.ac.za>
> declaimed the following in comp.lang.python:
>
>
> > Thanks , but , this work for an ordered substrings , just like what we
> > had   ['0132442\n', '13\n', '24\n'] , I would like to remove all
> > substrings from the list , example
> >
> > ['0134314244133', '132443', '234']
> >
> >
> > 2nd and 3rd strings are also substrings from the 1st one , so it should
> > be removed
> >
>
> 	One of us must be using a non-standard definition of "substring" as
> "234" does not appear anywhere within either "132443" or
> "0134314244133".

I don't understand "234" either, but I can see some pattern in
"132443".

"132443" is a 'subsubstring' "0134314244133" because:

0134314244133
-##----###-#-

Maybe "234" is just a typo, and it should be "243".

def subsubstr(a, b):
  if b == '':
    return True
  if a == '':
    return False
  else:
    if a[0] == b[0]:
      return subsubstr(a[1:], b[1:])
    else:
      return subsubstr(a[1:], b)

I can give you more efficient, index-based sulution, but this
one looks nicer.

BranoZ




More information about the Python-list mailing list