How to return the smallest average within a nested loop
I need to return the smallest average value of word similarities within a list (which I can do) but I don't know how to assign a word string value to the average values, for example in a list ['my', 'bro', 'myline'] of course bro would have the least word comparison value and hence I need 'bro' to be returned along with the comparison value (which I already know how to...just need to know how to assign values within nested loops).
final_tup = () ave_list =  for word in final_list: word1 = word sum = 0 for word in final_list: word2 = word if word2 != word1: num = cossim(word1,word2) sum = sum + num average = float(sum/(len(final_list)-1)) ave_list.append(average)
from operator import itemgetter # Make the word list. word_list = ['my', 'bro', 'myline'] # Do your code here to create ave_list # Fetch the min index and min value of ave_list min_index, minvalue = min(enumerate(ave_list), key = itemgetter(1) ) # Now get the word at the same min index location. min_word = word_list[min_index]