wordnet semantic similarity: how to refer to elements of a pair in a list? can we sort dictionary according to the value?

Terry Reedy tjreedy at udel.edu
Sun Oct 7 15:53:35 EDT 2012


On 10/7/2012 12:15 PM, Token Type wrote:

> In this case, I need to use loop to iterate each element in the above
> pairs. How can I refer to each element in the above pairs, i.e. pairs
> = [(car, automobile), (gem, jewel), (journey, voyage) ]. What's the
> index for 'car' and for 'automobile'? Thanks for your tips.

 >>> pairs = [('car', 'automobile'), ('gem', 'jewel')]
 >>> pairs[0][0]
'car'
 >>> pairs[1][1]
'jewel'
 >>> for a,b in pairs: a,b

('car', 'automobile')
('gem', 'jewel')

-- 
Terry Jan Reedy




More information about the Python-list mailing list