[Python-ideas] English builtins for Python

Steve Howell showell30 at yahoo.com
Thu Jun 21 20:14:16 CEST 2007


--- Arnaud Delobelle <arno at marooned.org.uk> wrote:
> 
> from random import randrange
> 
> ABIGNUMBER = 100000 # or should it be THEBIGNUMBER?
> 
> class ArticleError(Exception): pass
> 
> def the(s):
>     try:
>         s = iter(s)
>         ret = s.next()
>         for el in s: raise ArticleError
>         return ret
>     except (StopIteration, TypeError):
>         raise ArticleError("'the' argument must be a
> singleton iterable")
> 
> def a(s):
>     try:
>         s = iter(s)
>         for i, el in enumerate(s):
>             if not randrange(i+1): ret = el
>             if i == ABIGNUMBER: return ret
>         return ret
>     except (NameError, TypeError):
>         raise ArticleError("'a' argument must be a
> non-empty iterable")

Good stuff, I like it.  Not sure I would actually use
it, but it's a good brainstorm... :)


> an = a # for convenience :)
> 

Of course!


       
____________________________________________________________________________________
Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.
http://get.games.yahoo.com/proddesc?gamekey=monopolyherenow  



More information about the Python-ideas mailing list