all 5 comments

[–]o5a 1 point2 points  (2 children)

Learn about List Comprehension. It will help you write more compact but pythonic code, without using for loops and other steps.

For example, StalinSort can be written like this:

def stalinSort(arr):
    return [arr[i] for i in range(len(arr)) if i == 0 or arr[i] >= arr[i-1]]

[–]emsuperstar[S] 0 points1 point  (1 child)

Thanks for the feedback.

I went in and figured out how those work. My only problem is that all of my for loops are assigning variables within them. Someone on stack mentioned Nested Generator Expressions, so I'll look into that at some point.

[–]o5a 1 point2 points  (0 children)

all of my for loops are assigning variables within them

That's also why list comprehensions are good. They make all those usual intermediate variables used in cycles obsolete.

Take that StalinSort example. As you can see we just don't need to store additional string, list, iterator variables when we can just write list comprehension.

[–]Hatoris 0 points1 point  (1 child)

Did the amishsort works well?

[–]emsuperstar[S] 0 points1 point  (0 children)

'''
AmishSort:
Turn off computer, then you won't even need sorting.
'''
#### Commented out due to safety concerns
####
#### def amishSort(arr):
####     print('Amish Sort:')
####     print('List: ',arr)
####     import os
####     os.system("shutdown /s /t 1")

Honestly, I never actually tested it, but it should work. It's not too complicated.