Jun-16-2019, 06:00 PM
from itertools import tee def last_current(iterable): """ Takes any kind of iterable and returns a interator which yields last and current element """ last, current = tee(iterable) next(current) return zip(last, current) def is_sorted(sequence): """ Consumes any kind of sequences, also Generators, which can be consumed only one time and do not have index access. """ for last, current in last_current(sequence): if last > current: return False return True
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!