Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Reverse Every Ascending by PetrStar
def reverse_ascending(items):
items.append(-1)
reverse = [items[0]]
result = []
for i in range(len(items) - 1):
if items[i] < items[i + 1]:
reverse += [items[i + 1]]
else:
if len(reverse) != 0:
reverse.reverse()
result += reverse
reverse = [items[i+1]]
if len(reverse) != 0:
reverse.reverse()
result += reverse
return result[:-1]
if __name__ == '__main__':
print("Example:")
print(reverse_ascending([]))
assert list(reverse_ascending([1, 2, 3, 4, 5])) == [5, 4, 3, 2, 1]
assert list(reverse_ascending([5, 7, 10, 4, 2, 7, 8, 1, 3])) == [10, 7, 5, 4, 8, 7, 2, 3, 1]
assert list(reverse_ascending([5, 4, 3, 2, 1])) == [5, 4, 3, 2, 1]
assert list(reverse_ascending([])) == []
assert list(reverse_ascending([1])) == [1]
assert list(reverse_ascending([1, 1])) == [1, 1]
assert list(reverse_ascending([1, 1, 2])) == [1, 2, 1]
# These "asserts" are used for self-checking and not for an auto-testing
print("Coding complete? Click 'Check' to earn cool rewards!")
Nov. 15, 2020