Home > other >  The use of Python: list with string
The use of Python: list with string

Time:09-23

Also don't know where is wrong, can't run, have more simple program, feel to write this a little tired, but seems to be no use to the list and string

CodePudding user response:

Loading different within the list, and then unified print

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:

 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:

reference 1st floor weixin_45903952 response:
load a different list respectively, and then unified print?

Where is that I write this is wrong

CodePudding user response:

reference ha li deer ah ~ 7 floor response:
Quote: refer to 1st floor weixin_45903952 response:
load a different list respectively, and then unified print?

That where I wrote the wrong

You add your code to the post, I can't play their own, I think you run, there is each person's performance and output at a time

CodePudding user response:

refer to the eighth floor weixin_45903952 response:
Quote: refer to 7th floor, the ritual deer ah ~ reply:

Quote: refer to 1st floor weixin_45903952 response:
load a different list respectively, and then unified print?

That where I wrote the wrong

You add your code to the post, I can't play their own, I think you run, there is every a person's success and output a

I know where is wrong, I copied the topic ls list of a comma, in the title is Chinese comma inside, should be changed to a comma in English
  • Related