1

would like to know what is the objective of update the built-in function from Python2 to Python 3, below is the code

# Python 2
list1 = [123, 'xyz', 'zara', 'abc']
list2 = [456, 700, 200]
print " Minimum of list 1 is : ", min(list1)  #answer is 123
print " Minimum of list 2 is : ", min(list2)  #answer is 200

#python 3
print ("Minimum of list 1 is : "), min(list1)

##----- TypeError: unorderable types: str() < int()

So, may i know how to address this problem in Python 3 and the objective to improve the built-in function. Thanks in advace for any advice and suggestion. Thanks

1 Answer 1

1

There is nothing to improve.

min and max just do 123 < "xyz".

In Python2 int is always less than str. In Python3 it's actually fixed, they are incomparable now (because there is actually no way to compare 42 and "dog" you know).

In your case I recommend to use filter to find the minimum among the values you actually want.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.