Count how many values in a list that satisfy certain condition

前端 未结 7 1415
醉话见心
醉话见心 2021-01-11 13:50

I have the following list,

mylist = [\'0.976850566018849\',
 \'1.01711066941038\',
 \'0.95545901267938\',
 \'1.13665822176679\',
 \'1.21770587184811\',
 \'1.         


        
7条回答
  •  醉梦人生
    2021-01-11 14:04

    If you want the values returned to you and stored in a list you could do:

    count = []
    for value in mylist:
        num = float(value)
        if num >= 1.3:
            count.append(value)
    

    If you want it to output the list just add:

    print(count)
    

    or if you want the count of the number of values that are greater add:

    print(len(count))
    

提交回复
热议问题