Re: [Tutor] Sorting a dictionary into a list cont'd

2012-05-08 Thread Prasad, Ramit
> Oh, and here's the error my program returns when it runs: > > Traceback (most recent call last): > File "/home/jacob/Dropbox/Shared_With_Chris_And_Logan/Jake's > Programs/Yet_To_Work_On/Synaptic/synaptic.py", line 57, in > neuron.smartest() > File "/home/jacob/Dropbox/Shared_With_Chris_

[Tutor] Sorting a dictionary into a list cont'd

2012-05-08 Thread Jacob Bender
Oh, and here's the error my program returns when it runs: Traceback (most recent call last): File "/home/jacob/Dropbox/Shared_With_Chris_And_Logan/Jake's Programs/Yet_To_Work_On/Synaptic/synaptic.py", line 57, in neuron.smartest() File "/home/jacob/Dropbox/Shared_With_Chris_And_Logan/Jake

Re: [Tutor] Sorting a dictionary by a value when the values are tuples

2011-03-05 Thread Steven D'Aprano
ranjan das wrote: This is a small example i created from operator import itemgetter temp={'4':(2,3), '2':(5,8)} print temp.items() new_temp=sorted(temp.items(), key=itemgetter(1) print new_temp Another syntax error. Please ensure that you test your code before posting. In this case, it's eas

[Tutor] Sorting a dictionary by a value when the values are tuples

2011-03-05 Thread ranjan das
This is a small example i created from operator import itemgetter temp={'4':(2,3), '2':(5,8)} print temp.items() new_temp=sorted(temp.items(), key=itemgetter(1) print new_temp I want to sort the dictionary by the value in the first element of the tuple ((2,3) and (5,8)) and then the second

Re: [Tutor] Sorting a dictionary on a value in a list.

2008-12-09 Thread Lie Ryan
On Mon, 08 Dec 2008 08:55:40 -0800, Lawrence Wickline wrote: > On Dec 6, 2008, at 12:41 AM, Lie Ryan wrote: >> >> In most cases, in processing involving networking, the bottleneck is >> the >> network speed itself. To speed things up by optimizing your own code >> might not make your download sign

Re: [Tutor] Sorting a dictionary on a value in a list.

2008-12-08 Thread Lawrence Wickline
On Dec 6, 2008, at 12:41 AM, Lie Ryan wrote: In most cases, in processing involving networking, the bottleneck is the network speed itself. To speed things up by optimizing your own code might not make your download significantly faster (getting 60 seconds faster is great for scripts that us

Re: [Tutor] Sorting a dictionary on a value in a list.

2008-12-06 Thread Lie Ryan
On Thu, 04 Dec 2008 10:48:54 -0800, Lawrence Wickline wrote: > Thanks for the help I think I got it. > > As far as lines go I believe it will be processing hundreds of thousands > of lines if not a million or more lines per run. I haven't gotten to do > a full run but it has been running acceptab

Re: [Tutor] Sorting a dictionary on a value in a list.

2008-12-04 Thread Lawrence Wickline
Thanks for the help I think I got it. As far as lines go I believe it will be processing hundreds of thousands of lines if not a million or more lines per run. I haven't gotten to do a full run but it has been running acceptably fast on my test files. I ended up putting it into a main fun

Re: [Tutor] Sorting a dictionary on a value in a list.

2008-12-03 Thread Kent Johnson
On Wed, Dec 3, 2008 at 7:58 PM, Lawrence Wickline <[EMAIL PROTECTED]> wrote: > how would I sort on bytes sent? You can't actually sort a dictionary; what you can do is sort the list of items. In this case each item will look be a tuple (filename, (bytes, bytes_sent)) and dict.items() will be a

[Tutor] Sorting a dictionary on a value in a list.

2008-12-03 Thread Lawrence Wickline
I am working on a reducer that needs to produce a sorted output of files sorted on their overall bandwidth use. I create a dictionary with the file name as the key (it is always unique) and in the values I am populating a list with the two values of bytes and bytes sent. Each entry looks like {fi

Re: [Tutor] Sorting a dictionary

2005-11-04 Thread Alan Gauld
Hi JOhan, > You see, I didn't put all the keys and values in the dicionary manually. > It was generated while parsing a file with some Python code, that's why > the dict is not in order. It wouldn't have mattered if you had done it manually. The order of a dictionary is calculated by Python dynam

Re: [Tutor] Sorting a dictionary

2005-11-04 Thread Kent Johnson
Johan Geldenhuys wrote: > Thanks, Danny. > > You see, I didn't put all the keys and values in the dicionary manually. > It was generated while parsing a file with some Python code, that's why > the dict is not in order. I just want to do it to read easier and look > something up. You want the

Re: [Tutor] Sorting a dictionary

2005-11-04 Thread Johan Geldenhuys
Thanks, Danny. You see, I didn't put all the keys and values in the dicionary manually. It was generated while parsing a file with some Python code, that's why the dict is not in order. I just want to do it to read easier and look something up. How will I then put my dict together again after

Re: [Tutor] Sorting a dictionary

2005-11-04 Thread Pujo Aji
Hallo,   you can also sort based on the values:   >>> list_of_nums = nums.items()>>> list_of_nums.sort(lambda x,y: cmp(x[1],y[1])) Cheers, pujo       On 11/4/05, Danny Yoo <[EMAIL PROTECTED]> wrote: On Fri, 4 Nov 2005, Johan Geldenhuys wrote:> In my new project I needed a dictionary with TCP/UDP p

Re: [Tutor] Sorting a dictionary

2005-11-04 Thread Danny Yoo
> ser_port = {'4401': 'ds-srvr', \ > '5427': 'sco-peer-tta', \ > '4446': 'n1-fwp', \ > '3734': 'synel-data', \ > '4447': 'n1-rmgmt', \ > '5745': 'fcopy-server', \ > '5990': 'wbem-exp-https', \ > '4026': 'as-debug', \ > '3724': 'battlenet'} Hi Johan, Just as a quick side note: all those

Re: [Tutor] Sorting a dictionary

2005-11-04 Thread Danny Yoo
On Fri, 4 Nov 2005, Johan Geldenhuys wrote: > In my new project I needed a dictionary with TCP/UDP port numbers as > keys and the service for that key as the value. I got the info from the > services file in Linux and compiled a dictionary as I needed. > > The only thing that I want to do is to

[Tutor] Sorting a dictionary

2005-11-04 Thread Johan Geldenhuys
Hi all, In my new project I needed a dictionary with TCP/UDP port numbers as keys and the service for that key as the value. I got the info from the services file in Linux and compiled a dictionary as I needed. The only thing that I want to do is to sort the dictionary from the smallest key num