Skip to content

Instantly share code, notes, and snippets.

@brainix
Last active September 3, 2020 06:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brainix/703b184743a005e4f6d16fa4ddf6b898 to your computer and use it in GitHub Desktop.
Save brainix/703b184743a005e4f6d16fa4ddf6b898 to your computer and use it in GitHub Desktop.
import random
def assertion_sort(list_):
try:
assert all(x <= y for x, y in zip(list_, list_[1:]))
except AssertionError:
random.shuffle(list_)
assertion_sort(list_)
if __name__ == '__main__':
assertion_sort(list_ := [2, 1, 4, 3, 5])
print(list_)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment