Message313636
Now I have thought about it and realized that
it's not suitable for islice.
But there's still a common use case to
drop some elements from the beginning or
ending of a iterable, which is also a main
reason why I wanted islice to support
negative values of start and stop.
So how about adding two functions
``drop_first`` and ``drop_last``
to do such things. They can be implemented
like this, in which way they support
arbitrary iterators::
def drop_first(iterable, n=1):
for _ in range(n):
next(iterable)
for e in iterable:
yield e
def drop_last(iterable, n=1):
dq = deque()
for _ in range(n):
dq.append(next(iterable))
for e in iterable:
dq.append(e)
yield dq.popleft() |
|
Date |
User |
Action |
Args |
2018-03-12 09:20:43 | tttnns | set | recipients:
+ tttnns, rhettinger, serhiy.storchaka |
2018-03-12 09:20:43 | tttnns | set | messageid: <1520846443.21.0.467229070634.issue33040@psf.upfronthosting.co.za> |
2018-03-12 09:20:43 | tttnns | link | issue33040 messages |
2018-03-12 09:20:42 | tttnns | create | |
|