python - Getting keys for specific a value in dictionary -


the reason why asking question because working huge datas.

in algorithm, need this:

users_per_document = [] documents_per_user = [] 

as understand names of dictionaries, need users clicked specific document , documents clicked specific user.

in case have "duplicated" datas, , both of them overflows memory , script gets killed after while. because use large data sets, have make in efficient way.

i think not possible need ask it, there way keys of specific value dictionary?

because if there way that, not need 1 of dictionaries anymore.

for example:

users_per_document["document1"] returns appropriate users,
need users_per_document.getkeys("user1") because return same thing documents_per_user["user1"]

if not possible, suggestion pleased..

if using python 3.x, can following. if 2.x, use .iteritems() instead.

user1_values = [key key,value in users_per_document.items() if value == "user1"] 

note: iterate on whole dictionary. dictionary isn't ideal data structure keys specific value, o(n^2) if have perform operation n times.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -