If I have a dictionary whose values are lists, how can slice that list based on indexes? For example:
a = {"x": [1,2,3,4], "y": [10,20,30,40]}
I have the list of indexes, called indexes = [0,2]
.
I want to get a = {"x": [1,3], "y": [10,30]}
. How can I do it without rebuilding the dictionary?
I know I can do it something like
{key: dict_name[key][indexes] for key in dict_name}
but I guess it might be inefficient because it re-builds the dictionary?
Thanks!