Apr-22-2024, 09:14 AM
The useful function
https://docs.python.org/3/library/iterto...s.pairwise
This isn't Pythonic:
itertools.pairwise
was added to Python 3.10.https://docs.python.org/3/library/iterto...s.pairwise
This isn't Pythonic:
range(len(something))
from itertools import pairwise from string import ascii_lowercase from random import choice, randint test_data = [ [choice(ascii_lowercase) for i in range(5)], [i for i in ascii_lowercase], [randint(1, 10) for i in range(10)], [i for i in range(10)], ] def is_sorted(iterable): for last, current in pairwise(iterable): if last > current: return False return True # test for data in test_data: print(f"'{'-'.join(map(str, data))}' is {'' if is_sorted(data) else 'not'} sorted")
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!