What do these two statements mean in Python?
distances[(clust[i].id,clust[j].id)]=distance(clust[i].vec,clust[j].vec)
d=distances[(clust[i].id,clust[j].id)]
I am guessing that the first statement assigns clust[i].id and clust[j].id keys of the distances map to the result of the distance(..) function. However, I am confused since lists are represented using [] and dictionaries using {} in Python. What's the correct answer?  
Dictionary literals use {}. Indexing operations use [], regardless of type.
distances[(clust[i].id,clust[j].id)]=distance(clust[i].vec,clust[j].vec)
distances is a dictionary where keys are tuples of probably integers and the value is the distance measured between them by the distance function.
in the second line:
d=distances[(clust[i].id,clust[j].id)]
the d variable is just assigned to that distance, accessing the dictionary value just assigned.
other answers provide the summary of what's a dictionary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With