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

2012-10-09 Thread Token Type
Thanks indeed for your tips. Now I understand the difference between tuples and dictionaries deeper. -- http://mail.python.org/mailman/listinfo/python-list

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

2012-10-08 Thread alex23
On Oct 9, 2:16 pm, Token Type wrote: > When I try my above codes, what puzzles me is that when > the data in the dictionary increase, some data become > missing in the sorted result. Quite odd. In the pairs, > we have {'journey':'voyage'} but in the sorted result no ( > 'journey-voyage',0.25) > >

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

2012-10-08 Thread Token Type
Thanks indeed for all your suggestions. When I try my above codes, what puzzles me is that when the data in the dictionary increase, some data become missing in the sorted result. Quite odd. In the pairs, we have {'journey':'voyage'} but in the sorted result no ('journey-voyage',0.25), which did

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

2012-10-08 Thread alex23
On Oct 9, 1:13 pm, Token Type wrote: > yes, thanks all your tips. I did try sorted with itemgetter. > However, the sorted results are same as follows whether I > set reverse=True or reverse= False. Isn't it strange? Thanks. That's because you're sorting each entry individually, not the entire res

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

2012-10-08 Thread Ian Kelly
On Mon, Oct 8, 2012 at 9:13 PM, Token Type wrote: > yes, thanks all your tips. I did try sorted with itemgetter. However, the > sorted results are same as follows whether I set reverse=True or reverse= > False. Isn't it strange? Thanks. First of all, "sorted" does not sort the list in place as

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

2012-10-08 Thread Token Type
Dear all, the problem has been solved as follows. Thanks anyway: >>> import nltk >>> from nltk.corpus import wordnet as wn >>> pairs = {'car':'automobile', 'gem':'jewel', 'journey':'voyage'} >>> list_simi=[] >>> for key in pairs: word1 = wn.synset(str(key) + '.n.01') word2 = wn.syn

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

2012-10-08 Thread Token Type
yes, thanks all your tips. I did try sorted with itemgetter. However, the sorted results are same as follows whether I set reverse=True or reverse= False. Isn't it strange? Thanks. >>> import nltk >>> from nltk.corpus import wordnet as wn >>> pairs = {'car':'automobile', 'gem':'jewel', 'journey'

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

2012-10-07 Thread Terry Reedy
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 fo

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

2012-10-07 Thread Mark Lawrence
25 Now it seems that I can calculate the semantic similarity for each groups in the above dictionary. However, I want to sort according to the similarity value in the result before print the result out. Can sort dictionary elements according to their values? This is one of the requirement in t

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

2012-10-07 Thread Token Type
m-jewel 0.125 Now it seems that I can calculate the semantic similarity for each groups in the above dictionary. However, I want to sort according to the similarity value in the result before print the result out. Can sort dictionary elements according to their values? This is one of the re

Re: Sort dictionary by value when value is a list

2008-11-14 Thread Chris Rebert
On Fri, Nov 14, 2008 at 10:26 AM, major-john <[EMAIL PROTECTED]> wrote: > I'm having trouble sorting a dictionary based on values when the values are > all lists, and i want to sort the list by key with the largest value lists > in decreasing size. > > Currently, I have the following: > > from oper

Re: Sort dictionary by value when value is a list

2008-11-14 Thread Vlastimil Brom
2008/11/14 major-john <[EMAIL PROTECTED]> > I'm having trouble sorting a dictionary based on values when the values are > all lists, and i want to sort the list by key with the largest value lists > in decreasing size. > > Currently, I have the following: > > from operator import itemgetter > > di

Sort dictionary by value when value is a list

2008-11-14 Thread major-john
I'm having trouble sorting a dictionary based on values when the values are all lists, and i want to sort the list by key with the largest value lists in decreasing size. Currently, I have the following: from operator import itemgetter dict = {'A': [(10, 20), (12, 18), (5, 11), (18, 25)], 'C': [

Re: sort dictionary by specific values

2007-08-18 Thread Arnau Sanchez
dorje tarap escribió: >2. > {8: (99, 99), 9: [(55, 67), (77, 66), (67, 88)], 4: [(45, 78), > (56, 78), (99, 78)], 5: (67, 77)} > > > I want to sort the entire dictionary based on the last values in each > line. First for [-1][0] and then[-1][0] Each "line" means each value in t

Re: sort dictionary by specific values

2007-08-18 Thread Gary Herron
dorje tarap wrote: > Hi, > > I need to perform some horrible functions in python I need to do, > using sort in a similar way that Excel can. > > With a dictionary like: > Code: ( text ) > > 1. > >>> d > 2. > {8: (99, 99), 9: [(55, 67), (77, 66), (67, 88)], 4: [(45, 78), > (56,

sort dictionary by specific values

2007-08-18 Thread dorje tarap
Hi, I need to perform some horrible functions in python I need to do, using sort in a similar way that Excel can. With a dictionary like: Code: ( text ) 1. >>> d 2. {8: (99, 99), 9: [(55, 67), (77, 66), (67, 88)], 4: [(45, 78), (56, 78), (99, 78)], 5: (67, 77)} I want to sort the ent

Re: Sort dictionary

2006-01-02 Thread Luis M. González
You can't get a dictionary ordered by values, but you can get a list of key-value pairs ordered by value: def sortByValue(myDict): x = sorted( [(v,k) for k,v in myDict.items()] ) return [(k,v) for v,k in x] For getting only the first two pairs: sortByValue(x)[:2] Hope this helps

Re: Sort dictionary

2006-01-02 Thread Luis M. González
This function returns a tuple of value-key pairs, sorted by value: >>> x = {'a':3, 'b':2, 'c':4} >>> def sortByValue(myDict): return sorted( [(v,k) for k,v in myDict.items()] ) If you want to get the first two value-key pairs: >>> sortByValue(x)[:2] [(2, 'b'), (3, 'a')] Hope this helps..

Re: Sort dictionary

2006-01-02 Thread Luis M. González
This function return a tuple of value-key pairs, sorted by value: >>> x = {'a':3, 'b':2, 'c':4} >>> def sortByValue(myDict): return sorted( [(v,k) for k,v in myDict.items()] ) If you want to get the first two value-key pairs: >>> sortByValue(x)[:2] [(2, 'b'), (3, 'a')] Hope this helps..

Re: Sort dictionary

2006-01-02 Thread Claudio Grondi
Markus Franz wrote: > Hi! > > I have: > > x = {'a':3, 'b':2, 'c':4} > > How can I sort x by value? (I tried using sorted() with x.items() - but I > didn't get a dictionary as response.) > > My second question: > How can I reduce the dictionary to 2 items (so delete everything after the > first

Sort dictionary

2006-01-02 Thread Markus Franz
Hi! I have: x = {'a':3, 'b':2, 'c':4} How can I sort x by value? (I tried using sorted() with x.items() - but I didn't get a dictionary as response.) My second question: How can I reduce the dictionary to 2 items (so delete everything after the first two items) Thanks in advance. Best regards