Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Simply clever. Congrats
What about sorted?
I like the different thikning
Haha love your solution ;)
This comment is hidden because it contains spoiler information about the solution
As bkaes said, you don't want to surprise the user by modifying the input list. Lists and dictionaries are examples of data types that are mutable, so when you change an input list in the local function space, you are also changing the input list in the caller space. This can be a useful feature of these data types, but requires special care sometimes.
Additionally, you could have just returned [lst[0], lst[-1]] instead of creating the tempor variable.
Since
min_max
isn't documented, you expect the argumentlst
to hold the following property:After all,
min_max
extracts information fromlst
, so it's not necessary to modify the list. Changing the list would surprise the user.That being said, your solution runs in O(n log n) compared to the optimal O(n). If you don't know the O-notation: if the list has
n
elements, your solution needs abouts * (n * log n)
operations to get the minimum (wheres
is some constant), whereas an optimal solution only usess' * n
operations (wheres'
is another constant). If you're interested in O-notation, search for "Big O notation" or "Landau notation".And why is it dangerous? Do you think I could lost some part of imput or is it a question of Best Practices?
I'm not really experienced programmer so thank you in advance for your answer.
A bit dangerous because you have modified the input list using the .sort() method. Sorting a copy or creating a new list using sorted avoids this situation.