现有一组同学绮梦,冷伊一,香凝,梓轩,零语,圣博;他们的生源地
分别为山东、山西、湖南、内蒙古,山东,山西.
(1)利用集合分别记录学生名单和生源地;
(2)利用集合构造出相同省份的学生名单。
我编写的代码:
student_name = ['绮梦','冷伊一','香凝','梓轩','零语','圣博']
student_name1 = set (student_name)
print (student_name1)
birthplace = ['山东','山西','湖南','内蒙古','山东','山西']
birthplace1 = set (birthplace)
print (birthplace1)
dictionary = dict(zip(student_name,birthplace))
print (dictionary)
for student_name,birthplace in dictionary.items():
dict.setdefault(birthplace,set()).add(student_name)
student = [ len(values) > 1]
printf(student)
需要达成的运行结果:
img
我当前运行的结果:
img