我正在試圖合併三個字典在一起。在Python中合併三個字典
我收到一個unsupported operand types
錯誤。
這裏是我的代碼:
def add_student():
global Snumber
global iCode
global kCode
Snumber = Student_number.get()
Sname = Student_name.get()
Ssurnname = Student_surname.get()
Sdetail = Student_detail.get()
i = Students(Snumber,Sname,Ssurnname,Sdetail)
Sinfo[Snumber]=[Sname,Ssurnname,Sdetail]
iName = Student_subject.get()
iCode = Student_code.get()
iMark1 = Student_Mark1.get()
iMark2 = Student_Mark2.get()
iMark3 = Student_Mark3.get()
iProject = Student_project.get()
j = Subjects(iName,iCode,iMark1,iMark2,iMark3,iProject)
SSubject[iCode]=[iName,iMark1,iMark2,iMark3,iProject]
kCourse = Degree_course.get()
kCode = Degree_code.get()
kYear = Degree_year.get()
v = Degrees(kCourse,kCode,kYear)
SDegree[kCode]=[kCourse,kYear]
popup_add()
student_list = (Sinfo.items() + SSubject.items() + SDegree.items())
print(student_list)
我相信我的問題是:
student_list = (Sinfo.items() + SSubject.items() + SDegree.items())
print(student_list)
這個例子對我來說看起來不完整。什麼是例如'SInfo'? – languitar
在問題標題中,您說合並字典,在問題的第一行中,您說他們是列表,然後最後說他們是字典。你需要更清楚一點。 – DavidG
可以打印類型(Sinfo)(和其他字典)和len(Sinfo.items())(和其他項目?) – Illusionist