c enum - how to do this in python?

Fernando Perez fperez528 at yahoo.com
Wed Mar 5 23:47:16 CET 2003

Anna wrote:

>> Reversing strings with [::-1] is more or less a divertissement,
> Actually, the more I play with it, the better I like it. It still looks
> wierd though... and I still want it to have a NAME. I like names. Names
> are a Good Thing. So - what's this mutant smilie called?

Well, that syntax has actually been valid for lists in python for a long
time.  It's just that none of the builtins supported it :)

But for those who use Numeric regularly, it's very natural.  It was
specifically added to python to support extended slicing for Numeric
arrays, I'm glad it's finally supported by the builtins.  It's incredibly
convenient, to say pick the even/odd entries from a list with:

r = range(20)
even = r[::2]
odd = r[1::2]

Unbeatable, heh?

So now you have it across python. Once you understand the syntax, you don't
need a name for it.  Or do you want strings to grow .even(), .odd(),
.odd_skipping_everyother(), .every_prime(), etc methods? Just kidding :)

My point is just that once the syntax becomes second nature to you, it stops
looking like a smiley and becomes a slice.  Trust me, you'll grow to love



More information about the Python-list mailing list