I have two lists x = ['high', 'low', 'high'] and y = ['volume', 'value', 'value']
And i would like to have a dict like {'volume': ['high'], 'value': ['low', 'high']}
How to do it simply? Thanks
I have two lists x = ['high', 'low', 'high'] and y = ['volume', 'value', 'value']
And i would like to have a dict like {'volume': ['high'], 'value': ['low', 'high']}
How to do it simply? Thanks
Simply, you can zip two list, if the key is not exist, you can create and array and append the new value. Otherwise you can directly append to array.
my_dict={}
x = ['high', 'low', 'high']
y = ['volume', 'value', 'value']
for x_value, y_value in zip(x, y):
if y_value in my_dict:
my_dict[y_value].append(x_value)
else:
my_dict[y_value]=[(x_value)]
print(my_dict)