Issue
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
Solution
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.
Answered By - Vadim Pushtaev
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.