python自定义函数传嵌套字典出错 10
all_guests={'Alice':{'apples':5,'pretzls':12},'Bob':{'hamsandwiches':3,'apples':2},'C...
all_guests = {'Alice':{'apples':5,'pretzls':12}, 'Bob':{'ham sandwiches':3,'apples':2}, 'Carol':{'cups':3,'apples pies':1}}def total_brought(guests,item): num_brought = 0 for k,v in guests.itmes(): num_brought = num_brought + v.get(item,0) return num_broughtprint('Number of things being brought:')print(' - Apples '+ str(total_brought(all_guests,'apples')))用来打印带来苹果的数量,嵌套的字典怎么传参数才对?
展开
1个回答
展开全部
应该是用大括号的 # create a mapping of state to abbreviationstates = { 'Oregon': 'OR', 'Florida': 'FL', 'California': 'CA', 'New York': 'NY', 'Michigan': 'MI'}# create a basic set of states and some cities in themcities = { 'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville'}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询