Checking if string starts with list element

Aahz Maruch aahz at netcom.com
Mon Aug 14 11:51:31 EDT 2000


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.
--
                      --- Aahz (Copyright 2000 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

Gun-toting Naderite / socialized medicine libertarian



More information about the Python-list mailing list