Posts: 4,559
Threads: 1,464
Joined: Sep 2016
i can easily extract the last item from a
list with
mylist.pop()
. is there an easy way to do that with an
iterator?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,559
Threads: 1,464
Joined: Sep 2016
(Oct-01-2021, 06:35 PM)Yoriz Wrote: import time.TimeMachine
, use the future
method to get the item at the end of the iterator.
i guess this must run the iterator since it could be a generator or such.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,559
Threads: 1,464
Joined: Sep 2016
(Oct-01-2021, 06:35 PM)Yoriz Wrote: import time.TimeMachine
, use the future
method to get the item at the end of the iterator.
i don't seem to have
time.TimeMachine. i'm still on Python 3.6. i hope to be on 3.9 soon.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,559
Threads: 1,464
Joined: Sep 2016
i did find something called
time_machine for CPython on Unix. it was a "PRE_LOAD" binary library that allowed setting fake clock values. it probably intercepted syscalls that get the time and added/subtracted a time offset. i think Linux can already do that in containers which would not let the same Python script control it (you'd have to create containers from Python and run something in them).
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,559
Threads: 1,464
Joined: Sep 2016
Oct-02-2021, 11:53 PM
(This post was last modified: Oct-02-2021, 11:54 PM by Skaperen.)
does reversed() work on iterators? ... nope!
Output:
lt2a/phil /home/phil 16> box try_rev.py
+----<try_rev.py>----+
| a=[1,2,3,4,5,6] |
| b=iter(a) |
| c=reversed(b) |
| print(c[0]) |
+--------------------+
lt2a/phil /home/phil 17> py try_rev.py
Traceback (most recent call last):
File "try_rev.py", line 3, in <module>
c=reversed(b)
TypeError: 'list_iterator' object is not reversible
lt2a/phil /home/phil 18>
i think it's time for me to create a function named
revit.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.