Python search by value

前端 未结 3 516
一个人的身影
一个人的身影 2021-01-06 05:44

I need a proper solution to search for a key in a nested data structures in Python. Lets assume that I have variable with value \'check\' and dict like this:



        
3条回答
  •  借酒劲吻你
    2021-01-06 06:18

    Simply iterate over the dictionary keys and check if check is one of the values of the value corresponding to the key. If you find it then give it to the next call.

    print next(key for key in SERVICES if 'check' in SERVICES[key])
    # domain
    

提交回复
热议问题