Home > other >  Python for help
Python for help

Time:09-17

CodePudding user response:

Data=https://bbs.csdn.net/topics/your demand list

Def function (data) :
The return data [1]

Data. Sort (key=function)
Print (data [0:10])

You can get the top 10

CodePudding user response:

Wrong, you this list is a space delimiter, not a comma, this list of data need to deal with, to avoid trouble, the regular match the


The import re
Data=https://bbs.csdn.net/topics/
you a list of data
Def function (data) :
STR="'. Join (data)
Return int ('. Join (re. The.findall (r "\ d +", STR)))

Data. Sort (key=function)
Print (data [0:10])

CodePudding user response:

 s=[[' Bai Anhua ', '86'], 
[' always on ', '70'],
[' ytm ', '92'],
[' z ', '88'],
[' XXX ', '66']]
S=sorted (s, key=lambda x: x [1], reverse=True)
S1=s [3] :
Sumnum=sum (float (s0 [1]) for s0 in s)
Maxnum=float (s [0] [1])
Minnum=float (s [1] [1])
Meannum=sumnum/len (s)
Print (' {}, maximum average minimum {} {} '. The format (maxnum minnum, meannum))
Stdsumnum=sum ((float (s0 [1]) - meannum) * * 2 for s0 in s)
Stdnum=stdsumnum/len (s)
Print (' {} {} standard deviation of variance. The format (stdsumnum stdnum))
Print (s1)
  • Related