-1

How does min() sort a list like this: ["abc", "abb", "aba"], in the end I know the output of min(["abc", "abb", "aba"]) will be "aba" but I'm not quite sure how it decides on which one to consider the min, does it sort by the string with the lowest sum of ord() for each character in the string? Or how does it sort it?

1 Answers1

0

It loops through each and every value and picks up the smallest one. Equivalent code:

def min(lst):
    me = lst[0]
    for i in range(1, len(lst)):
        if lst[i] < me:
            me = lst[i]

    return me

It's a naive implementation but it gives you an idea.

Tarik
  • 10,810
  • 2
  • 26
  • 40