Open pinguinium99 opened 11 months ago
This may be an intentional bug 😄 I would argue though that using the tmp
variable is a missed opportunity to show off Python unpacking:
def foo_3(x, y, z):
if x > y:
y, x = x, y
if y > z:
y, z = z, y
return [x, y, z]
This does not work for the exceptional case where z is the lowest value. The following code should solve the problem (but sorts it in descending order):
def foo_3(x, y, z):
if z > y and y > x:
x, y, z = z, y, x
if y > x and x > z:
x, y ,z = y, x, z
return [x, y, z]
Mine wasn't intended to fix the bug (which may be an intentional feature), but just to point out that the tmp
variable can be avoided using Python features.
in cfexercises1.py the function foo_3 will not order the three values if the smallest value is in the z position in the function.
returns:
(6, 1, 8)