一个班的学生姓名和成绩如下,打印出及格学生的姓名及成绩:
A
|
B
|
C
|
D
|
E
|
F
|
G
|
67
|
41
|
88
|
99
|
65
|
55
|
27
|
C:
-
#include <stdio.h>
-
-
typedef struct {
-
char name[255];
-
int score;
-
} testInfoT;
-
-
int main()
-
{
-
testInfoT ti[] = {
-
{"A", 67},
-
{"B", 41},
-
{"C", 88},
-
{"D", 99},
-
{"E", 65},
-
{"F", 55},
-
{"G", 27},
-
};
-
-
for (int i = 0; i < sizeof(ti) / sizeof(testInfoT); i++){
-
if (ti[i].score > 60){
-
printf("%s:%d\n", ti[i].name, ti[i].score);
-
}
-
}
-
-
return 0;
-
}
python:
-
testInfo = {
-
"A":67, \
-
"B":41, \
-
"C":88, \
-
"D":99, \
-
"E":65, \
-
"F":55, \
-
"G":27}
-
-
print(filter(lambda x : x[1] > 60, testInfo.items()))
filter(function, sequence):对sequence中的item依次执行function(item),将执行结果为True的item组成一个List/String/Tuple(取决于sequence的类型)返回.
阅读(812) | 评论(0) | 转发(0) |