程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python: use the set to construct a list of students in the same province.

編輯:Python

Now there is a group of students named Qimeng , Lengyiyi , Xiangning , Zixuan , Zero language , San Bo ; Their birthplace
Shandong 、 shanxi 、 hunan 、 Inner Mongolia , Shandong , shanxi .
(1) Use the collection to record the list of students and the place of origin ;
(2) Use the set to construct the student list of the same province .

The code I wrote :
student_name = [' Dream ',' Lengyiyi ',' Xiangning ',' Zixuan ',' Zero language ',' San Bo ']
student_name1 = set (student_name)
print (student_name1)
birthplace = [' Shandong ',' shanxi ',' hunan ',' Inner Mongolia ',' Shandong ',' shanxi ']
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)
Operational results to be achieved :


Results of my current run :


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved