python - Map over a dict -


i'm trying this:

list(map(lambda x: x.name, my_dict)) 

where my_dict dict of form k, v v object , v.name defined.

the problem is using key k x want use value v.

in other words: how map on values of dict?

ps want avoid my_dict[x] using concurrent.futures , won't passing full dict separate threads.

to retrieve view of values, may use .values method.

map(callable, my_dict.values()) 

obviously, map trivial callables can avoided in python using list or generator comprehensions.

[x.name x in my_dict.values()]  # creates list: non-lazy (x.name x in my_dict.values())  # creates generator: lazy 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -