On 10/12/07, Dick Moores <[EMAIL PROTECTED]> wrote:
>
> Please see the code and it's output here:
> <http://www.rcblue.com/Python/buggy_For_Web.py>
>
>
> I'm attempting to eliminate the elements (strings) of lstA that are
> not well-formed in that they contain at least one character that is
> not in the string astr.



Hi Dick,

If your interested, this could be done succinctly with set types. (no
iterating required!)

def well_formed(word):
    return not set('#.<@') & set(word)

>>> well_formed('porkpie')
True
>>> well_formed('p#rkpie')
False

And then it seems you are coming to terms with list comprehensions...

my_list = [word for word in my_list if well_formed(my_word)]

OR...

my_list = filter(well_formed, my_list)

Ian.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to