max() not finding actual maximum value in list

This question already has an answer here:

  • How do I parse a string to a float or int in Python? 22 answers

  • what you are doing is like following:

    a = ['1','3','10','5']
    print sorted(a)
    

    output

    ['1', '10', '3', '5']
    

    therefore the first step is converting to float/int

    a = ['1','3','10','5']
    print sorted(a)
    print sorted(map(int,a))
    print max(a)
    print max(map(int,a))
    

    output

    ['1', '10', '3', '5']
    [1, 3, 5, 10]
    5
    10
    
    链接地址: http://www.djcxy.com/p/48432.html

    上一篇: 将字典的值更改为整数

    下一篇: max()没有在列表中找到实际的最大值