enhancing slicing
Duncan Booth
duncan at NOSPAMrcp.co.uk
Thu Aug 23 10:18:56 EDT 2001
gbreed at cix.compulink.co.uk wrote in news:9m31fp$27s$1 at thorium.cix.co.uk:
>> My proposal is to introduce a new operator, for instance # (count):
>> v[5 # 2]
>> Extract 2 elements starting at 5: [ v[5], v[6] ]. Equivalent to v[5:5+2]
>
> I don't think # is right, because it's already used for comments. But
> perhaps :][: would do the trick. So it'd be v[5 :][: 2]. It's more
> complex, but looks nice. And doesn't introduce any new punctuation into
> the language. Shall I start on the PEP?
What is wrong with just defining yourself a function to do this? Not
everything has to be done with operators:
def enhslice(seq, low, len):
return seq[low:low+len]
seems to do everything you are asking for, and has the benefit of being
available today, and not complicating the language.
--
Duncan Booth duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?
More information about the Python-list
mailing list