Minimum and maximum in one pass
Task
Write a function min_max(zoznam) that finds both the smallest and the largest item of a non-empty list in one pass and returns them as a pair (minimum, maximum).
Do not use min, max or sorting.
Examples
Call
print(min_max([3, 9, 1, 4]))
Expected output
(1, 9)
Rules
Find both values with a loop - no
min,maxor sorting.
After you submit, 5 hidden tests will also check your solution: one item, negative numbers, equal items, decimal numbers, a sorted list.
Python starts the first time you run code.
Ctrl+Enter runs the program. Tab indents. Press Esc, then Tab, to leave the editor.
Input (stdin)
Each line = one call to input().
Output
Hints
Try it yourself first. Each hint reveals a little more - and lowers the reward a little.
Signed out, hints are free - but no XP is awarded either.
Solution
The solution unlocks after the last hint.