comparing all values of a list to regex

Delaney, Timothy tdelaney at avaya.com
Thu Sep 26 19:39:56 EDT 2002


> From: Alex Martelli [mailto:aleax at aleax.it]
> 
> I don't see exactly what value the call to map adds in your case.

None at all in this case - good catch :) I'll blame it on feeling really
buggered yesterday (am today too for some reason - thank goodness it's only
about 7 hours until the weekend :)

> > # Find out which list to append to
> > 
> > match_list = match_all
> > 
> > if not matches:
> >     match_list = match_none
> > elif matches == 1:
> >     match_list = match_one
> > elif matches != len(alist):
> >     match_list = match_some
> > 
> > match_list.append(alist)
> 
> Yes, choosing a list first and then appending to the chosen
> list is nicer, but you cannot do that within the original
> specs (for all I know the match_some list might grow
> unbearably large over time, in this case).

Hmm - why not? Ignoring that the original specs didn't actually *have* that
case, choosing the list to append to, or doing it in-place is merely an
implementation detail. Of course, you would need instead to do something
like:

match_list = None

if not matches:
    match_list = match_none
elif matches == 1:
    match_list = match_one
elif matches == len(alist):
    match_list = match_all

if match_list is not None:
    match_list.append(alist)

Tim Delaney




More information about the Python-list mailing list