How to filter dictionary keys based on its corresponding values

前端 未结 6 1102
南笙
南笙 2021-01-30 04:50

I have:

dictionary = {\"foo\":12, \"bar\":2, \"jim\":4, \"bob\": 17}

I want to iterate over this dictionary, but over the values instead of the

6条回答
  •  故里飘歌
    2021-01-30 05:43

    Use items or iteritems on dictionary. Something like:

    list = []
    for k, v in dictionary.iteritems():
      if v > 6:
        list.append(k)
    print list
    

提交回复
热议问题