I’m trying to write a function that returns the largest and smallest number in a string. However, not all numbers in the string are 1 digit numbers – some are 2 or 3 digits long.
Examples:
JavaScript
x
4
1
high_and_low("1 2 3 4 5") # return "5 1"
2
high_and_low("1 2 -3 4 5") # return "5 -3"
3
high_and_low("12 9 314 4 -57") # return "314 -57"
4
This exercice originates from codewars.com
Advertisement
Answer
It’s really easy to do with a list comprehension and int conversion
JavaScript
1
4
1
def high_and_low(nums)
2
nums = [int(n) for n in nums.split()]
3
return max(nums), min(nums)
4