forked from kingname/SourceCodeofMongoRedis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
37 lines (24 loc) · 1.08 KB
/
Copy pathexample.py
File metadata and controls
37 lines (24 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import redis
client = redis.Redis(host='xx.xx.xx.xx')
all_class = ['algorithm',
'computer',
'history',
'circuit_design',
'math']
def all_student():
students = client.sunion(*all_class)
return len(students)
def in_a_and_in_b(class_a, class_b):
students = client.sinter(class_a, class_b)
return len(students)
def in_a_not_in_b(class_a, class_b):
students = client.sdiff(class_a, class_b)
return len(students)
def in_a_or_in_b(class_a, class_b):
students = client.sunion(class_a, class_b)
return len(students)
if __name__ == '__main__':
print(f'当前一共有{all_student()}名学生至少选了一门课。')
print(f'当前选了math,没有选computer的学生有:{in_a_not_in_b("math", "computer")}名学生至少选了一门课。')
print(f'当前选了math,也选computer的学生有:{in_a_and_in_b("math", "computer")}名学生至少选了一门课。')
print(f'当前选了math,或者选computer的学生有:{in_a_or_in_b("math", "computer")}名学生至少选了一门课。')