Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Solution

Hassan K
Hassan K
1,504 Points

My code was significantly longer than the code in the video, would it be considered "wrong" or not pythonic?

if __name__ != "__main__":
    def min_finder(k):
        i = 0
        for k[i] in k:
            if k[i] == min(k):
                print (f"The lexicographically first word is {k[i]}")
                i += 1

2 Answers

Dane Parchment
Dane Parchment
Treehouse Moderator 11,020 Points

Not exactly, whether code is "long" or not doesn't mean the solution is "wrong". Typically the most important thing when determining if a solution is the wrong one or not is whether or not it accomplishes the task it set out to do. After that it's performance.

If the code you wrote accomplishes the task and performs well (and not worst than another solution), then it comes down to a compromise between efficiency (line numbers) and maintainability (readability/extendability). There is a fad in the python community of writing these "elegant" one-liners that can do a lot of things in one line of code. While this may be neat to flex your python skills they typically make for bad maintainable code, so I'd refrain from that.

But little rant out of the way, nothing about your code would be wrong or non-pythonic just because it has a few more lines than someone else's solution. It's just another solution among a multitude each with their own benefits and trade-offs.

arthur alonso
arthur alonso
Full Stack JavaScript Techdegree Student 1,636 Points

Here is my answer based on a function just introduced in the last course right before this workshop on 'beginning python' track, "Introducing Dictionaries" by my favorite teacher, Ashley Boucher!

def first_finder(list):
    return sorted(list)[0]

Just wanted to thank her!