c enum - how to do this in python?
Alex Martelli
aleax at aleax.it
Thu Mar 6 06:00:07 EST 2003
Fernando Perez wrote:
> 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 :)
And its name was ("long-form" or "extended") slicing -- and still is.
> So now you have it across python. Once you understand the syntax, you
> don't need a name for it.
But you do -- and the name is, "a long-form slicing of the string". A
shorter (nick-)name might help if you must use it often, but that's
optional, of course.
> Or do you want strings to grow .even(), .odd(),
> .odd_skipping_everyother(), .every_prime(), etc methods? Just kidding :)
I think you're misreading the OP's request, and that she asked about
the name of the [::-1] construct, NOT asked for named _methods_ to be
added to string objects to duplicate slicings' functionality.
> 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
> it.
"A slice" is, e.g., slice(None,None,-1). "A slicing" is the operating which
consists in applying a slice object to a container, as in:
container[::-1]
which is equivalent to:
container[slice(None,None,-1)]
It's exactly the same distinction as between "an index" and "an indexing":
container[foo]
this is an indexing, and foo is the index used in this indexing.
Yeah, I know, this IS a bit pedantic -- and the distinction between
indexing and slicing is fuzzy (if foo=slice(11,22,3) precedes the
indexing container[foo], for example;-)...
Alex
More information about the Python-list
mailing list