CodePudding user response:
Loading different within the list, and then unified printCodePudding user response:
Ls=,55,93,75,56,47,67,90,24,88 [85]Chengji={' fail ': [],' pass ': [],' good ': [],' optimal ': []}
For I in ls:
If I & lt; 60:
Chengji [' fail ']. Append (I)
The else:
If i<75:
Chengji [' pass ']. Append (I)
The else:
If i<90:
Chengji [r]. 'good' append (I)
The else:
Chengji [' optimal ']. Append (I)
For the key and the value in chengji. The items () :
Print (' % s, % d, the result is: % s' % (key, len (value), [I for I in value]))
CodePudding user response:
ls=,55,93,75,56,47,67,90,24,88 [85]
Chengji={' fail ': [],' pass ': [],' good ': [],' optimal ': []}
For I in ls:
If I & lt; 60:
Chengji [' fail ']. Append (I)
The else:
If i<75:
Chengji [' pass ']. Append (I)
The else:
If i<90:
Chengji [r]. 'good' append (I)
The else:
Chengji [' optimal ']. Append (I)
For the key and the value in chengji. The items () :
Print (' % s, % d, the result is: % s' % (key, len (value), [I for I in value]))
CodePudding user response:
import itertools as it
L=[56, 85, 55, 93, 75, 47, 67, 90, 24, 88]
E=[[' failed 'if x & lt; 60 else' pass 'if 60 & lt;=x<75 else' good 'if 75 & lt;=x<90 else' good ', 1) for x l] in
E.s ort (key=lambda x: x [0])
O=[[k, len (list (g))) for k, g in it. The groupby (e, lambda x: x [0])]
Print (o)
CodePudding user response:
import pandas as pd
L=[56, 85, 55, 93, 75, 47, 67, 90, 24, 88]
P=pd. DataFrame ({' A ': [' failed' if x & lt; 60 else 'pass' if 60 & lt;=x<75 else 'good' if 75 & lt;=x<90 else 'good' for x in l]})
Print (dict (p.g roupby (' A '). The size ()))
CodePudding user response:
ls=,55,93,75,56,47,67,90,24,88 [85]
Chengji={' fail ': [],' pass ': [],' good ': [],' optimal ': []}
For I in ls:
If I & lt; 60:
Chengji [' fail ']. Append (I)
The else:
If i<75:
Chengji [' pass ']. Append (I)
The else:
If i<90:
Chengji [r]. 'good' append (I)
The else:
Chengji [' optimal ']. Append (I)
For the key and the value in chengji. The items () :
Print (' % s, % d, the result is: '% (key, len (value)), end=' ')
For I in value:
Print (I, end=' ')
Print ()
CodePudding user response: