Return a dict from map function

newb here, hello! I’m using map() function to iterate a list of Tickers (strings) through OHLCV download function with multiprocessing. As a result, I receive a list of dataframes.

All_coins_history = Shark_pool.map(refractor_get_history, Tickers)

As my dataframes with history have just Dataframe[["Open", "High", "Low", "Close", "Volume"]] format, there is no way for me to know which data from All_coins_history list is for which Ticker. What is the clean way to create, for example, a dictionary instead of list, where each dataframe would have its Ticker as a key?

Answer

Use zip() to pair up the ticker symbols with the result of the mapping, then call dict() to create the dictionary.

all_coins_history = dict(zip(Tickers, Shark_pool.map(refractor_get_history, Tickers)))