fast way to return the key based on dictionary value in python -


i have 2 dictionaries:

dict1 = agent_id:agent_email dict2 = user_id:agent_id 

i want create dictionary:

agent_id: list of user_ids associated agent_id 

how search dict2 each agent_id dict1 , return associated key? i've been told creating list of keys , searching slow. there faster way?

the question suggested dupe not tell me i'd know. i'm trying search values without creating separate list. also, once have value, how corresponding key?

edit information need in dict2. question how @ it. each agent_id associated multiple user_id's. want create dict looks this:

{agent_id_1:(user_id_1, user_id_2, user_id_45), agent_id_2:(user_id_987), agent_id_3:(user_id_10, user_id_67)...etc} 

based on 1 of answers, i'm looking created 'reverse dict'. i'm don't understand yet, values in dict2 (the agent_ids) not unique. way go?

try this.

 key1, val1 in dict1.iteritems():         key2,val2 in dict2.iteritems():             if key1 == val2:                 print key2 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -