french_set = {"张三","许木","王鹏","邓江","胡图","李明","周刚"}
art_set = {"刘梅","王鹏","谢娜","李明","刘强"}
math_set = {"张三","乔九","许木","大大","葛优","王鹏"}
#方式三---->集合推导式的方式
fr_art_not_ar3 = {s for s in french_set if s not in art_set}
print(fr_art_not_ar3)
#3.统计每个学生选修的课程数量
all_set = french_set.union(art_set) # 并集,也可以用 “|”
all_set2 = french_set | art_set
print(all_set) #获取到所有学生,去重
print(all_set2)
all_list = [*french_set, *art_set, *math_set] #利用list列表可以重复的特性,“*”解包
for student in all_set:
count = all_list.count(student)
print(f"{student}\t 选修了 {count} 门课程")
#总结:
# set 集合运算符
#交集 intersection &
#差集 difference -
#并集 union |
#解包 *
#集合推导式写法 set = {i表达式 for i in 集合}
#集合推导式写法 set = {i表达式 for i in 集合 if 条件}