Python字典如何通过一部分字找到含有这些字所有的value

2025-04-13 11:11:23
推荐回答(2个)
回答1:

  1. 首先,你的数据结构定义错了,没有这种结果。只有{‘box1':[xx,xx,xx]}

  2. for key,vals in 你的字典对象:

    print '%s has these balls ' %key

    for val in vals:

    if val.find('ball') >= 0:

    print val

回答2:

用find方法找到有ball的字符,打印出来就行了