I have multiple lists of equal length I want to compare in order to append some words in a dictionary of list. I've already compared those lists to get the max number for each index.
maxlist = [2,9,6,4,8] #This is the list of max number from the three different lists
a_list = [2,1,4,2,8]
b_list = [1,9,6,3,4]
c_list = [0,3,2,4,1]
Now, I have another list of words of the same length:
words = ["boy", "girl", "git", "tall", "boss"]
What I want to do here is compare each list to maxlist, and if the number in maxlist is found in either of the three list at the same index, I want to create a dictionary of list that will append words to that specific list. So my end result will be like:
For index 0, maxlist is found in a_list, so I will have:
{a_list: ["boy"]}
for index 1, maxlist is found in b_list, so I will have:
{a_list: ["boy"], b_list: ["girl"]}
After comparing all each list with maxlist, I want to have:
{a_list: ["boy", "boss"], b_list:["girl","git"], c_list: ["tall"]}
I used three list as an example here, but in my case I have 40 lists. Is there any effective way to implement this? I am currently stuck. Here is the code I'm currently writing:
label_data = {}
for i in range(len(maxlist)):
if maxlist[i] > 1: #I don't want to consider a max of 1.
if maxlist == a_list[i]:
if a_list in label_data:
label_data["a_list"].append(words[i])
else:
dates_dict["key"] = [words[i]]
Not sure if the above code will work fine, plus I have to keep constructing if function for all the lists. Is there any effective way to solve this, and please post your code.
Thanks