Right, but for getting all the pairs in order, I don't think that ordering them during insertion is helpful – it would be better to just sort them all at once afterwards.
On Sun, Jun 15, 2014 at 6:09 PM, Kevin Squire <[email protected]> wrote: > By default, OrderedDicts are in the order you insert the pairs, but I > don't see anything wrong about allowing the user to change that order if > she chooses. And sorting by value isn't difficult either. > > Of course, using priority queue might fit the OP's use case better. > > Cheers, > Kevin > > > On Sun, Jun 15, 2014 at 2:33 PM, Stefan Karpinski <[email protected]> > wrote: > >> Isn't an OrderedDict in the order you inserted key-value pairs though? >> This is more like a priority queue than that since you presumably want to >> count terms and then take the N most common – or sort them all in order of >> occurrence. >> >> >> On Sun, Jun 15, 2014 at 5:11 PM, Kevin Squire <[email protected]> >> wrote: >> >>> At one point while I was developing the OrderedDict class in >>> DataStructures.jl, I made it possible to sort it (and sorting regular >>> dictionaries returned an OrderedDict. It should be pretty easy to add that >>> functionality back. You would need to load the DataStructures.jl package, >>> of course. >>> >>> Cheers, >>> Kevin >>> >>> >>> On Sun, Jun 15, 2014 at 12:23 PM, Stefan Karpinski < >>> [email protected]> wrote: >>> >>>> You can use a comprehension over the Dict to get an array of count, >>>> string pairs and then sort that in place, which avoids some copying. >>>> >>>> On Jun 15, 2014, at 3:03 PM, TR NS <[email protected]> wrote: >>>> >>>> >>>> >>>> On Sunday, June 15, 2014 10:48:16 AM UTC-4, Stefan Karpinski wrote: >>>>> >>>>> Works for me. What version of Julia are you using? Note that if you >>>>> have the integer before the string in each tuple, you can just sort the >>>>> array. >>>>> >>>>> >>>> >>>> Turns out I was trying to sort a Dict. Once I wrapped it in collect() >>>> it worked. Seems a little ugly though to first have to convert it to an >>>> array of tuples and then sort using `x->x[2]`. Might there be a way to sort >>>> Dicts directly? (Though obviously the result would not be Dict). >>>> >>>> Good to know about the integer being before the string, though it won't >>>> help in this particular case. The Dict stores a word key and frequency >>>> value. I am counting the frequency of words in a corpus. >>>> >>>> Thanks. >>>> >>>> >>> >> >
