Skip to content

Instantly share code, notes, and snippets.

@TruncatedDinoSour
Created June 21, 2023 21:35
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 TruncatedDinoSour/4d4c767ac076797251da65312a11db01 to your computer and use it in GitHub Desktop.
Save TruncatedDinoSour/4d4c767ac076797251da65312a11db01 to your computer and use it in GitHub Desktop.
very fast and good sorting algo
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""best sorting algorithm"""
from secrets import SystemRandom
from warnings import filterwarnings as filter_warnings
RAND: SystemRandom = SystemRandom()
def issorted(lst: list[int]) -> bool:
for idx in range(len(lst)):
for jdx in range(idx + 1, len(lst)):
if lst[jdx] < lst[idx]:
return False
return True
def sort(lst: list[int]) -> None:
while not issorted(lst):
RAND.shuffle(lst)
def main() -> int:
"""entry/main function"""
l: list[int] = list(range(5))
RAND.shuffle(l)
print(l)
sort(l)
print(l)
return 0
if __name__ == "__main__":
assert main.__annotations__.get("return") is int, "main() should return an integer"
filter_warnings("error", category=Warning)
raise SystemExit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment