Why not break when a match is found
if self.choices:
match = False
for choice in self.choices:
if choice == value:
match = True
break
if not match:
raise BadValueError('Property %s is %r; must be one of %r' %
(self.name, value,self.choices))
Maybe faster to make self.choices a dictionary.
The keys are in a hash table and that is faster then linear searching
self.choices = { choice1:True, choice2:True }
......
if self.choices:
if not self.choices.get(value):
raise BadValueError('Property %s is %r; must be one of %r' %
(self.name, value,self.choices))
2008/10/13 Andy Freeman <[EMAIL PROTECTED]>:
>
> google/appengine/db/__init__.py starting at line 401 is:
> if self.choices:
> match = False
> for choice in self.choices:
> if choice == value:
> match = True
> if not match:
> raise BadValueError('Property %s is %r; must be one of %r' %
> (self.name, value,
> self.choices))
>
> It could be:
> if value not in (self.choices or (value,)):
> raise BadValueError('Property %s is %r; must be one of %r' %
> (self.name, value,
> self.choices))
>
> "not in" will stop when it finds a match and may be faster for each
> element checked.
>
> Note that making self.choices a set would make the "not in" test O(1).
>
>
>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---