Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Solution

fahad lashari
fahad lashari
7,693 Points

How would one achieve this without the use of the built in min() function?

I'd like to know how someone may achieve this without using the min() function. Much appreciated in advance

2 Answers

Emmanuel Mejia
Emmanuel Mejia
5,885 Points

You can also create a very basic function by using sorted and calling the 1st index spot for example i have two functions that accomplish the same thing.

def alph_order(list):
    print(sorted(list)[0])

def alph_order(list):
    new_order = sorted(list)
    print(new_order[0])

The most easy to follow is me sorting the list using "sorted" and assigning it to "new_order" and then return or print the 1st index spot of "new_order"

Steven Parker
Steven Parker
229,744 Points

The "less than" operator (<) will identify alphabetical order when used on strings. So you could loop through the list, comparing each entry to the previous one, and saving the one that compares "least" in a temporary variable. The "min" value will be in that variable when the loop finishes.