Python字典如何通过一部分字找到含有这些字所有的value 10
{'box1':{'apple','orange','football','baseball'},'box2':{'basketball','cherry','blueb...
{'box1': {'apple', 'orange', 'football', 'baseball'}, 'box2': { 'basketball', 'cherry', 'blueberry'}
期望输出是
box1 has these balls:
football
baseball
box2 has these liver samples:
basketball
谢谢! 展开
期望输出是
box1 has these balls:
football
baseball
box2 has these liver samples:
basketball
谢谢! 展开
2个回答
展开全部
首先,你的数据结构定义错了,没有这种结果。只有{‘box1':[xx,xx,xx]}
for key,vals in 你的字典对象:
print '%s has these balls ' %key
for val in vals:
if val.find('ball') >= 0:
print val
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询