- Published on
CodeWars: 7kyu – The Highest Profit wins
I am exercising to get back into Python. Even though the solution to this exercise is quite straightforward, you could tweak the code a little bit so that it runs a little faster.
max(), the list would need to be iterated over 2 times. You could rewrite the code so that you only iterate once over the array. Overall I choose to stick with my initial solution as it is better readable, thus making it easier to maintain in the long run.
def min_max(lst): ''' Exercise: https://www.codewars.com/kata/the-highest-profit-wins/train/python Example: min_max([1, 2, 3, 4, 5]) => [1, 5] Args: lst: A list of numbers Returns: A list with two entries of the min and the max value of the list ''' return [min(lst), max(lst)]