【发布时间】:2018-09-25 16:25:17
【问题描述】:
我在尝试追加字典时遇到了一些麻烦,我真的不知道如何使用它,因为每次我尝试运行我的代码时,它都会说“'str' object has no attribute 'append'”...我有这样的东西......
oscars= {
'Best movie': ['The shape of water','Lady Bird','Dunkirk'],
'Best actress':['Meryl Streep','Frances McDormand'],
'Best actor': ['Gary Oldman','Denzel Washington']
}
所以我想创建一个新的类别,然后我想创建一个循环,用户可以输入任意数量的被提名者......
newcategory=input("Enter new category: ")
nominees=input("Enter a nominee: ")
oscars[newcategory]=nominees
addnewnominees= str(input("Do you want to enter more nominees: (yes/no):"))
while addnewnominees!= "No":
nominees=input("Enter new nominee: ")
oscars[newcategory].append(nominees)
addnewnominees= str(input("Do you want to enter more nominees: (yes/no):"))
有谁知道如何在字典中使用追加?
【问题讨论】:
标签: python string list dictionary append