[Python-ideas] List Revolution
Stephen J. Turnbull
stephen at xemacs.org
Sat Sep 10 04:38:55 CEST 2011
Christopher King writes:
> We must make first one, second 2, and third 3, like it is supposed
> to be.
There's a better way:
def first (sequence): return sequence['one'] # <wink/>
def second (sequence): return sequence[1]
def third (sequence): return sequence[2]
def fourth (sequence): return sequence[3]
def fifth (sequence): return sequence[4]
def sixth (sequence): return sequence[5]
def seventh (sequence): return sequence[6]
def eighth (sequence): return sequence[7]
There's probably an Ordinal module that would allow you to generate
such functions to your heart's content.
I'll have to wait for Guido's pronouncement about whether it's "more
Pythonic" as well as "just plain better" though.
More information about the Python-ideas
mailing list