Python Forum
last pass of for x in iterator:
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
last pass of for x in iterator:
#11
more_itertools actually already implements the feature
>>> from more_itertools import islice_extended
>>> list(islice_extended(range(10), None, -2))
[0, 1, 2, 3, 4, 5, 6, 7]
>>> list(islice_extended(range(10), None, -1))
[0, 1, 2, 3, 4, 5, 6, 7, 8]
Reply
#12
i could end up with a rather huge list so i'd rather do the one-behind generator. this is to be run on my own computers, so installing stuff from pip is not an issue. more_itertools sure has a lot of methods.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#13
(May-20-2019, 06:47 AM)Gribouillis Wrote: For a nice API, you could improve itertools.islice() by allowing a negative stop argument.

Yes please. I miss this feature also. I want to have also reversible iterators (for finite sequences).
If you have a solution to reverse a infinite sequence, tell us LOL
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#14
(May-20-2019, 09:44 PM)DeaD_EyE Wrote: If you have a solution to reverse a infinite sequence, tell us LOL
import itertools

from time_machine import future, present, step_back_in_time

for item in itertools.islice(infinite_sequence, future, present, step_back_in_time):
    print(item)
Shifty Shifty Shifty Shifty Shifty Shifty Shifty
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to pass encrypted pass to pyodbc script tester_V 0 856 Jul-27-2023, 12:40 AM
Last Post: tester_V
  prime numbers with iterator and generator cametan_001 8 1,869 Dec-17-2022, 02:41 PM
Last Post: cametan_001
  resetting an iterator to full Skaperen 7 6,973 Feb-20-2022, 11:11 PM
Last Post: Skaperen
  popping an iterator Skaperen 11 3,698 Oct-03-2021, 05:08 PM
Last Post: Skaperen
  q re glob.iglob iterator and close jimr 2 2,234 Aug-23-2021, 10:14 PM
Last Post: perfringo
  Problem with an iterator grimm1111 9 4,314 Feb-06-2021, 09:22 PM
Last Post: grimm1111
  Multi-class iterator Pedroski55 2 2,385 Jan-02-2021, 12:29 AM
Last Post: Pedroski55
  Pass by object reference when does it behave like pass by value or reference? mczarnek 2 2,557 Sep-07-2020, 08:02 AM
Last Post: perfringo
  is a str object a valid iterator? Skaperen 6 5,636 Jan-27-2020, 08:44 PM
Last Post: Skaperen
  discard one from an iterator Skaperen 1 1,991 Dec-29-2019, 11:02 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020