[Python-ideas] More useful slices

Chris Barker chris.barker at noaa.gov
Mon Feb 2 17:35:11 CET 2015


On Mon, Feb 2, 2015 at 8:11 AM, Chris Barker - NOAA Federal <
chris.barker at noaa.gov> wrote:

> It would be nice if there was more Kongo as to why it was rejected,
>

Wow -- weird auto-correct! That was supposed to be "info".

That's what I get for trying to write these notes on a phone on the bus...

Sorry,

 -Chris





> but it was, indeed, rejected.
>
> I also recall a lot of drawn out threads about more compact syntax for a
> for loop over integers, such as making the integer object iterable:
>
> for I in 10:
>     pass
>
> Which were also all rejected.
>
> Unless someone comes up with a compelling argument that something has
> changed, it seems this conversation has been had already.
>
> -Chris
>
>
>
> On Feb 2, 2015, at 7:02 AM, Neil Girdhar <mistersheik at gmail.com> wrote:
>
> But it is meaningful to have a range with an unspecified stop.  That's
> itertools.count.
>
> On Sunday, February 1, 2015 at 12:27:53 PM UTC-5, Steven D'Aprano wrote:
>>
>> On Sun, Feb 01, 2015 at 04:13:32PM +0100, Todd wrote:
>> > Although slices and ranges are used for different things and
>> implemented
>> > differently, conceptually they are similar: they define an integer
>> sequence
>> > with a start, stop, and step size.
>>
>> I'm afraid that you are mistaken. Slices do not necessarily define
>> integer sequences. They are completely arbitrary, and it is up to the
>> object being sliced to interpret what is or isn't valid and what the
>> slice means.
>>
>> py> class K(object):
>> ...     def __getitem__(self, i):
>> ...             print(i)
>> ...
>> py> K()["abc":(2,3,4):{}]
>> slice('abc', (2, 3, 4), {})
>>
>>
>> In addition, the "stop" argument to a slice may be unspecified until
>> it it applied to a specific sequence, while range always requires
>> stop to be defined.
>>
>> py> s = slice(1, None, 2)
>> py> "abcde"[s]
>> 'bd'
>> py> "abcdefghi"[s]
>> 'bdfh'
>>
>> It isn't meaningful to define a range with an unspecified stop, but it
>> is meaningful to do so for slices.
>>
>>
>> In other words, the similarity between slices and ranges is not as close
>> as you think.
>>
>>
>> --
>> Steven
>> _______________________________________________
>> Python-ideas mailing list
>> Python... at python.org
>> https://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150202/24635a0f/attachment.html>


More information about the Python-ideas mailing list