nested exceptions?

Aahz aahz at pythoncraft.com
Sun Apr 21 13:33:07 EDT 2002


In article <mailman.1019401778.10328.python-list at python.org>,
Nick Arnett <narnett at mccmedia.com> wrote:
> [mailto:python-list-admin at python.org]On Behalf Of Aahz
>>
>> That is, if you're checking N items against a list with M items, you're
>> gonna have poor performance algorithmically.  Note that I said "avoid";
>> using 'in' against a list is sometimes the simplest and most
>> straightforward approach, and if it's not being done in a loop, it won't
>> cause too much of a performance hit.
>
>So... although the following is such a short list that I don't think it
>really matters (except that, come to think of it, it is in a loop), it's bad
>form?
>
>if self.item[0:3] in ('Mon','Tue','Wed','Thu','Fri','Sat','Sun'):
>	self.item = self.item[4:]

Yup.  Use a dict, even if constructing the dict looks uglier.  There's
actually a double whammy in your example, because the tuple must be
constructed each time through the if.
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

What if there were no rhetorical questions?



More information about the Python-list mailing list