Created
July 20, 2023 04:28
-
-
Save MobCat/7182a01c8f58ef789b02e46fc64ab849 to your computer and use it in GitHub Desktop.
Meme sorter in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/env/Python3.10.4 | |
#/MobCat (2023) | |
# Meme sorter | |
# max'in pop | |
# Is it good? No that's the point. | |
# I just wanted to see if my dumb idea worked. | |
# But I feel like this dumb idea should already excist. | |
import random | |
import timeit | |
# Builds a random list to sort | |
# The list contains 10 to 30 items | |
# the items range from 1 to 100 | |
# No idea if this works with negitvie numbers. | |
list_length = random.randint(10, 30) | |
random_list = [random.randint(1, 100) for _ in range(list_length)] | |
# just print out the unsorted list for the user | |
print(random_list) | |
# Define a blank new lost to sort into | |
sort_list = [] | |
# While the lenth of the unsorted list is grater then 0 | |
# Find the largest number in the unsoted list | |
# Chuck the largest number at the new list | |
# remove the largest number from the unsorted list | |
# rinse and repeat untill you run our of items in the unsorted list | |
while len(random_list) > 0: | |
sort_list.append(max(random_list)) | |
random_list.pop(random_list.index(max(random_list))) | |
# Print our sorted list | |
#print(sort_list) | |
# Cheat print our sorted list in revers order so now | |
# its sorted from smalest to largest. | |
print(sort_list[::-1]) | |
# Tells use how fast this while meme took to run in nanoseconds. | |
print(f"Execution time: {timeit.default_timer():.2f} ns") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment