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) 

Answers


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] 

Need Your Help

How can I delete the contents of a folder from the command prompt in windows?

deployment command-line msbuild

I am writing a deployment script using MSBuild. I want to clean my web directories prior to copying all the new files in. My current "Clean" target looks like this:

What needs to be in a .war file to deploy a Flex application?

flex ant flexbuilder

I've been using Flex Builder 3 to create Flex applications that are part of larger Flex / Java project using LiveCycle Data Services. Flex Builder creates and deploys the .war file, which is conve...