This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tttnns
Recipients tttnns
Date 2018-03-10.09:18:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1520673526.96.0.467229070634.issue33040@psf.upfronthosting.co.za>
In-reply-to
Content
``islice()`` does not support negative values for start or stop,
which does not matter for plain iterators.
However, for some cases, we have a sized iterable object
which is not subscriptable, using ``islice()`` makes
code ugly::

    d = OrderedDict()
    for i in range(10): d[i] = i
    dv = d.keys()
    # dv is a KeysView which is a sized iterable

    # now I wanna get a slice of dv which does not contain the last element
    islice(dv, len(dv) - 1)

As it shows, I have to use ``len(dv)`` to get its length.

For sized iterable objects, ``islice()`` could
support negative values for start or stop.
In this way, the above code can be written like this::

    islice(dv, -1)

For iterable objects which is not sized,
it could still be not supported::

    islice(iter(range(10)), -1)

raises a ValueError as its original behavior.
History
Date User Action Args
2018-03-10 09:18:47tttnnssetrecipients: + tttnns
2018-03-10 09:18:46tttnnssetmessageid: <1520673526.96.0.467229070634.issue33040@psf.upfronthosting.co.za>
2018-03-10 09:18:46tttnnslinkissue33040 messages
2018-03-10 09:18:46tttnnscreate