Thanks indeed for your tips. Now I understand the difference between tuples and
dictionaries deeper.
--
http://mail.python.org/mailman/listinfo/python-list
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)
>
>
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
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
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
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
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'
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
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
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
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
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
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': [
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
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,
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
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
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..
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..
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
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
21 matches
Mail list logo