Dec-07-2020, 02:11 PM
I think that naming can be improved in this example.
IMHO this can be expressed in more pythonic way.
This sort is in-place i.e. it can be applied only to mutable data types (immutables will raise TypeError as they don't support item assignment). Out of built-in mutable data types only list (and bytearray) are accessible by index (sets are unordered and dicts have keys and not indices). So naming parameter as list_ or similar represents much better the sorting ability than A.
Instead of antipattern of
IMHO this can be expressed in more pythonic way.
This sort is in-place i.e. it can be applied only to mutable data types (immutables will raise TypeError as they don't support item assignment). Out of built-in mutable data types only list (and bytearray) are accessible by index (sets are unordered and dicts have keys and not indices). So naming parameter as list_ or similar represents much better the sorting ability than A.
Instead of antipattern of
range(len())
one can write this instead:def insertion_sort(list_): for i, _ in enumerate(list_): for j in reversed(range(i)): current, next_ = j, j+1 if list_[next_] < list_[current]: list_[current], list_[next_] = list_[next_], list_[current] else: breakThe only difference is that there will be one wasted cycle at the beginning (i = 0).
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.