Checking if string starts with list element

Kevin Digweed Kevin.Digweed at dial.pipex.com
Mon Aug 14 12:07:00 EDT 2000


Aahz Maruch wrote:
> 
> In article <31575A892FF6D1118F5800600846864D4C71D3 at intrepid>,
> Simon Brunning  <SBrunning at trisystems.co.uk> wrote:
> >
> >I have a list of strings:
> >romans = ['aqueduct', 'sanitation', 'roads', 'irrigation', 'medicine',
> >'education', 'wine', 'public baths', 'order']
> >
> >And I have a single string:
> >us = 'wine, women and song.'
> >
> >I want to know whether my sting *starts with* one of the strings in my list.
> 
> Alex gave you half an answer.  Put your list of strings into a
> dictionary, chop the first element out of your comma-delimited string,
> then do a dict lookup.

I thought of something similar, but what if the string is "public baths
are wonderful things" ?
The problem, from what I can see, is based on substring recognition, not
'words'.

Cheers, Kev.



More information about the Python-list mailing list