Re: how to sort a list of tuples with custom function

2017-08-04 Thread Ho Yeung Lee
lif abs(lo1[1] - lo2[1]) == 1 and lo1[0] == lo2[0]: > > >>> return 1 > > >>> else: > > >>> return 0 > > >>> > > >>> > > >>> sorted(testing1, key=lambda x: (isneighborlocation.get(x

Re: how to sort a list of tuples with custom function

2017-08-04 Thread Ho Yeung Lee
;> > >>> > >>> sorted(testing1, key=lambda x: (isneighborlocation.get(x[0]), x[1])) > >>> > >>> return something like > >>> [(1,2),(3,3),(2,5)] > > >> I think you are trying to sort a list of two-dimensional points into a >

Re: how to sort a list of tuples with custom function

2017-08-03 Thread Ho Yeung Lee
> > > >>> elif abs(lo1[0] - lo2[0]) == 1 and lo1[1] == lo2[1]: > > > >>> return 1 > > > >>> elif abs(lo1[1] - lo2[1]) == 1 and lo1[0] == lo2[0]: > > > >>> return 1 > > > >>> else

Re: how to sort a list of tuples with custom function

2017-08-03 Thread Ho Yeung Lee
;>> return 1 > > >>> elif abs(lo1[1] - lo2[1]) == 1 and lo1[0] == lo2[0]: > > >>> return 1 > > >>> else: > > >>> return 0 > > >>> > > >>> > > >>> sorted(testing1,

Re: how to sort a list of tuples with custom function

2017-08-02 Thread Ho Yeung Lee
;>> elif abs(lo1[1] - lo2[1]) == 1 and lo1[0] == lo2[0]: > >>> return 1 > >>> else: > >>> return 0 > >>> > >>> > >>> sorted(testing1, key=lambda x: (isneighborlocation.get(x[0]), x[1])) > >>> > >

Re: how to sort a list of tuples with custom function

2017-08-02 Thread Peter Otten
mbda x: (isneighborlocation.get(x[0]), x[1])) >>> >>> return something like >>> [(1,2),(3,3),(2,5)] >> I think you are trying to sort a list of two-dimensional points into a >> one-dimensiqonal list in such a way thet points that are close together >

Re: how to sort a list of tuples with custom function

2017-08-01 Thread Ho Yeung Lee
return 1 > >> else: > >> return 0 > >> > >> > >> sorted(testing1, key=lambda x: (isneighborlocation.get(x[0]), x[1])) > >> > >> return something like > >> [(1,2),(3,3),(2,5)] > > I think you are trying

Re: how to sort a list of tuples with custom function

2017-08-01 Thread Glenn Linderman
lo2[1]) == 1 and lo1[0] == lo2[0]: return 1 else: return 0 sorted(testing1, key=lambda x: (isneighborlocation.get(x[0]), x[1])) return something like [(1,2),(3,3),(2,5)] I think you are trying to sort a list of two-dimensional points into a one-dimensiqonal list in such a wa

Re: how to sort a list of tuples with custom function

2017-08-01 Thread Piet van Oostrum
lo2[0]: > return 1 > else: > return 0 > > > sorted(testing1, key=lambda x: (isneighborlocation.get(x[0]), x[1])) > > return something like > [(1,2),(3,3),(2,5)] I think you are trying to sort a list of two-dimensional points into a one-dimensiqonal lis

Re: how to sort a list of tuples with custom function

2017-08-01 Thread Ho Yeung Lee
i tried with testing1.sort(key=lambda x: x[0]) but only first element of tuple are grouped then i expect to sort with custom function if difference between first element of tuple and another first element of tuple is less than some value and do for second element too, goal to segmentation of bla

how to sort a list of tuples with custom function

2017-08-01 Thread Ho Yeung Lee
def isneighborlocation(lo1, lo2): if abs(lo1[0] - lo2[0]) < 7 and abs(lo1[1] - lo2[1]) < 7: return 1 elif abs(lo1[0] - lo2[0]) == 1 and lo1[1] == lo2[1]: return 1 elif abs(lo1[1] - lo2[1]) == 1 and lo1[0] == lo2[0]: return 1 else: return 0 sort

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Chris Angelico
On Sun, May 26, 2013 at 1:38 PM, Steven D'Aprano wrote: > On Sun, 26 May 2013 03:23:44 +1000, Chris Angelico wrote: > >> Does adding 1 to a random >> number make it less random? It adds determinism to the number; can a >> number be more deterministic while still no less random? >> >> Ah! I know. T

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Dan Sommers
On Sun, 26 May 2013 03:38:12 +, Steven D'Aprano wrote: > ... adding a constant to a random variable still leaves it equally > random. Adding, multiplying, dividing or subtracting a constant from a > random variable X just shifts the possible values X can take ... That's mathematically true, b

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Chris Angelico
On Sun, May 26, 2013 at 1:09 PM, Steven D'Aprano wrote: > You're right, all my dice are eight-sided and complex: > > 1+0i > 1+1i > 1-1i > -1+0i > -1+1i > -1-1i > > > :-) Now THAT is a dice of win! >> Now, I have here with me >> a set used for maths drill (to be entirely accurate, what I have her

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Steven D'Aprano
On Sun, 26 May 2013 03:23:44 +1000, Chris Angelico wrote: > Does adding 1 to a random > number make it less random? It adds determinism to the number; can a > number be more deterministic while still no less random? > > Ah! I know. The answer comes from common sense: [snip spurious answer] I kno

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Steven D'Aprano
On Sun, 26 May 2013 01:41:58 +1000, Chris Angelico wrote: > On Sun, May 26, 2013 at 12:28 AM, Steven D'Aprano > wrote: >> On Sat, 25 May 2013 19:14:57 +1000, Chris Angelico wrote: >> >>> def random_number(): >>> return 7 >> >> I call shenanigans! That value isn't generated randomly, you just

RE: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Carlos Nepomuceno
> Date: Fri, 24 May 2013 23:05:17 -0700 > Subject: Re: help how to sort a list in order of 'n' in python without using > inbuilt functions?? > From: lokeshkopp...@gmail.com [...] > ya steven i had done the similar logic bu

RE: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Carlos Nepomuceno
> Date: Sun, 26 May 2013 03:23:44 +1000 > Subject: Re: help how to sort a list in order of 'n' in python without using > inbuilt functions?? > From: ros...@gmail.com > To: python-list@python.org > > On Sun, May 26, 201

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Chris Angelico
On Sun, May 26, 2013 at 3:17 AM, Carlos Nepomuceno wrote: > def f(x): > return x+1 > > or you can just go: > > f(roll_d6()) Hmm. Interesting. So now we have a question: Does adding 1 to a random number make it less random? It adds determinism to the number; can a number be more deterministic

RE: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Carlos Nepomuceno
> Date: Sun, 26 May 2013 01:41:58 +1000 > Subject: Re: help how to sort a list in order of 'n' in python without using > inbuilt functions?? > From: ros...@gmail.com > To: python-list@python.org > > On Sun, May 26, 20

RE: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Carlos Nepomuceno
> From: steve+comp.lang.pyt...@pearwood.info > Subject: Re: help how to sort a list in order of 'n' in python without using > inbuilt functions?? > Date: Sat, 25 May 2013 14:28:33 + > To: python-list@python.org > > On

RE: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Carlos Nepomuceno
> To: python-list@python.org > From: breamore...@yahoo.co.uk > Subject: Re: help how to sort a list in order of 'n' in python without using > inbuilt functions?? > Date: Sat, 25 May 2013 13:01:06 +0100 [...] > In my book this

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Chris Angelico
On Sun, May 26, 2013 at 12:28 AM, Steven D'Aprano wrote: > On Sat, 25 May 2013 19:14:57 +1000, Chris Angelico wrote: > >> def random_number(): >> return 7 > > I call shenanigans! That value isn't generated randomly, you just made it > up! I rolled a die *hundreds* of times and not once did it

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Mark Lawrence
On 25/05/2013 15:28, Steven D'Aprano wrote: On Sat, 25 May 2013 19:14:57 +1000, Chris Angelico wrote: def random_number(): return 7 I call shenanigans! That value isn't generated randomly, you just made it up! I rolled a die *hundreds* of times and not once did it come up seven! Lie

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Jussi Piitulainen
Roy Smith writes: > In article <78192328-b31b-49d9-9cd6-ec742c092...@googlegroups.com>, > lokeshkopp...@gmail.com wrote: > > > On Friday, May 24, 2013 1:34:51 PM UTC+5:30, lokesh...@gmail.com wrote: > > > i need to write a code which can sort the list in order of 'n' > > > without use builtin fu

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Fábio Santos
On 25 May 2013 15:35, "Steven D'Aprano" < steve+comp.lang.pyt...@pearwood.info> wrote: > > On Sat, 25 May 2013 19:14:57 +1000, Chris Angelico wrote: > > > def random_number(): > > return 7 > > I call shenanigans! That value isn't generated randomly, you just made it > up! I rolled a die *hundre

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Steven D'Aprano
On Fri, 24 May 2013 23:05:17 -0700, lokeshkoppaka wrote: > On Saturday, May 25, 2013 11:27:38 AM UTC+5:30, Steven D'Aprano wrote: >> tally = 0 >> for item in list_of_items: >> if item == 0: >> tally = tally + 1 >> >> print "The number of zeroes equals", tally > > > ya steven i had d

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Steven D'Aprano
On Sat, 25 May 2013 19:14:57 +1000, Chris Angelico wrote: > def random_number(): > return 7 I call shenanigans! That value isn't generated randomly, you just made it up! I rolled a die *hundreds* of times and not once did it come up seven! -- Steven -- http://mail.python.org/mailman/lis

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Dave Angel
On 05/25/2013 10:03 AM, Roy Smith wrote: In article <74e33270-a79a-4878-a400-8a6cda663...@googlegroups.com>, lokeshkopp...@gmail.com wrote: ya steven i had done the similar logic but thats not satisfying my professor he had given the following constrains 1. No in-built functions should be u

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Roy Smith
In article <74e33270-a79a-4878-a400-8a6cda663...@googlegroups.com>, lokeshkopp...@gmail.com wrote: > ya steven i had done the similar logic but thats not satisfying my professor > he had given the following constrains > 1. No in-built functions should be used > 2. we are expecting a O(n) solut

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Roy Smith
In article <78192328-b31b-49d9-9cd6-ec742c092...@googlegroups.com>, lokeshkopp...@gmail.com wrote: > On Friday, May 24, 2013 1:34:51 PM UTC+5:30, lokesh...@gmail.com wrote: > > i need to write a code which can sort the list in order of 'n' without use > > builtin functions > > > > can anyone h

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Mark Lawrence
On 25/05/2013 09:54, Carlos Nepomuceno wrote: lol def absolute(x): return x if x>0 else -x def reach(x): y=[] z=0 while z In my book this is another fail as lists are inbuilt (yuck!) and so is the add function that'll be called for z+=1. -- If you're using GoogleCrap™ pl

RE: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Carlos Nepomuceno
lol http://search.dilbert.com/comic/Random%20Nine > Date: Sat, 25 May 2013 19:14:57 +1000 > Subject: Re: help how to sort a list in order of 'n' in python without using > inbuilt functions?? > From: ros...@gmail.com > To: python-l

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Chris Angelico
On Sat, May 25, 2013 at 7:10 PM, Carlos Nepomuceno wrote: > >> Date: Sat, 25 May 2013 19:01:09 +1000 >> Subject: Re: help how to sort a list in order of 'n' in python without using >> inbuilt functions?? >> From

RE: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Carlos Nepomuceno
> Date: Sat, 25 May 2013 19:01:09 +1000 > Subject: Re: help how to sort a list in order of 'n' in python without using > inbuilt functions?? > From: ros...@gmail.com > To: python-list@python.org [...] > Very good. You are now i

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Chris Angelico
On Sat, May 25, 2013 at 6:54 PM, Carlos Nepomuceno wrote: > lol > > def absolute(x): > return x if x>0 else -x > > def reach(x): > y=[] > z=0 > while z y.append(z) > z+=1 > return y Very good. You are now in a position to get past the limitations of a restricte

RE: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Carlos Nepomuceno
lol def absolute(x):     return x if x>0 else -x def reach(x):     y=[]     z=0     while z Date: Sat, 25 May 2013 18:47:24 +1000 > Subject: Re: help how to sort a list in order of 'n' in python without using > inbuilt functions?? > From: ros...@gmail.com > To: python-l

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Chris Angelico
On Sat, May 25, 2013 at 6:43 PM, Carlos Nepomuceno wrote: > > lol I forgot to include this monkey patch! ;) > > def length(l): > x=0 > y=l[:] > while y: > x+=1 > y.pop() > return x Nice. Now eliminate abs (easy) and range. :

RE: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Carlos Nepomuceno
> Date: Sat, 25 May 2013 18:28:32 +1000 > Subject: Re: help how to sort a list in order of 'n' in python without using > inbuilt functions?? > From: ros...@gmail.com > To: python-list@python.org > > On Sat, May 25, 201

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Chris Angelico
On Sat, May 25, 2013 at 5:53 PM, Carlos Nepomuceno wrote: > >> Date: Fri, 24 May 2013 23:05:17 -0700 >> 1. No in-built functions should be used > count[2] = len(l) Fail! :) ChrisA -- http://mail.python.org/mailman/listinfo/python-list

RE: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-25 Thread Carlos Nepomuceno
> Date: Fri, 24 May 2013 23:05:17 -0700 > Subject: Re: help how to sort a list in order of 'n' in python without using > inbuilt functions?? > From: lokeshkopp...@gmail.com > To: python-list@python.org [...] > ya steven i ha

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread Chris Angelico
On Sat, May 25, 2013 at 4:05 PM, wrote: > ya steven i had done the similar logic but thats not satisfying my professor > he had given the following constrains > 1. No in-built functions should be used > 2. we are expecting a O(n) solution > 3. Don't use count method And now you finally admit

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread lokeshkoppaka
On Saturday, May 25, 2013 11:27:38 AM UTC+5:30, Steven D'Aprano wrote: > On Fri, 24 May 2013 22:39:06 -0700, lokeshkoppaka wrote: > > > > > On Saturday, May 25, 2013 10:54:01 AM UTC+5:30, Chris Angelico wrote: > > > > >> In that case, you're not really ordering them, you're counting them. >

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread Steven D'Aprano
On Fri, 24 May 2013 22:39:06 -0700, lokeshkoppaka wrote: > On Saturday, May 25, 2013 10:54:01 AM UTC+5:30, Chris Angelico wrote: >> In that case, you're not really ordering them, you're counting them. >> Look at the collections module; you can very easily figure out how >> many of each there are,

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread rusi
On May 25, 10:15 am, lokeshkopp...@gmail.com wrote: > On Friday, May 24, 2013 1:34:51 PM UTC+5:30, lokesh...@gmail.com wrote: > > i need to write a code which can sort the list in order of 'n' without use > > builtin functions > > > can anyone help me how to do? > >  Note: > the list only contains

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread Chris Angelico
On Sat, May 25, 2013 at 3:39 PM, wrote: > On Saturday, May 25, 2013 10:54:01 AM UTC+5:30, Chris Angelico wrote: >> On Sat, May 25, 2013 at 3:15 PM, wrote: >> >> > On Friday, May 24, 2013 1:34:51 PM UTC+5:30, lokesh...@gmail.com wrote: >> >> >> i need to write a code which can sort the list in o

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread lokeshkoppaka
On Saturday, May 25, 2013 10:54:01 AM UTC+5:30, Chris Angelico wrote: > On Sat, May 25, 2013 at 3:15 PM, wrote: > > > On Friday, May 24, 2013 1:34:51 PM UTC+5:30, lokesh...@gmail.com wrote: > > >> i need to write a code which can sort the list in order of 'n' without use > >> builtin functions

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread Chris Angelico
On Sat, May 25, 2013 at 3:15 PM, wrote: > On Friday, May 24, 2013 1:34:51 PM UTC+5:30, lokesh...@gmail.com wrote: >> i need to write a code which can sort the list in order of 'n' without use >> builtin functions >> >> can anyone help me how to do? > > Note: > the list only contains 0's,1's,2's

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread lokeshkoppaka
On Friday, May 24, 2013 1:34:51 PM UTC+5:30, lokesh...@gmail.com wrote: > i need to write a code which can sort the list in order of 'n' without use > builtin functions > > can anyone help me how to do? Note: the list only contains 0's,1's,2's need to sort them in order of 'n' -- http://mail.

RE: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread Carlos Nepomuceno
, 24 May 2013 01:04:51 -0700 > Subject: help how to sort a list in order of 'n' in python without using > inbuilt functions?? > From: lokeshkopp...@gmail.com > To: python-list@python.org > > i need to write a code which can sort the list in order of 'n'

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread Dave Angel
On 05/24/2013 04:04 AM, lokeshkopp...@gmail.com wrote: i need to write a code which can sort the list in order of 'n' without use builtin functions can anyone help me how to do? You could sort, but you couldn't print out the results, so what's the point? In Python 3.3 at least, print() is a

Re: help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread Chris Angelico
On Fri, May 24, 2013 at 6:04 PM, wrote: > i need to write a code which can sort the list in order of 'n' without use > builtin functions > can anyone help me how to do? > -- > http://mail.python.org/mailman/listinfo/python-list http://lmgtfy.com/?q=sorting+algorithm http://www.catb.org/esr/faqs

help how to sort a list in order of 'n' in python without using inbuilt functions??

2013-05-24 Thread lokeshkoppaka
i need to write a code which can sort the list in order of 'n' without use builtin functions can anyone help me how to do? -- http://mail.python.org/mailman/listinfo/python-list

Re: How to sort a list of strings on a substring

2009-10-06 Thread n00m
Here you are: LogList = [\ "inbound tcp office 192.168.0.125 inside 10.1.0.91 88", "inbound tcp office 192.168.0.220 inside 10.1.0.31 2967", "inbound udp lab 172.24.0.110 inside 10.1.0.6 161", "inbound udp office 192.168.0.220 inside 10.1.0.13 53"] LogList.sort(key=lambda x: x[x.

Re: How to sort a list of strings on a substring

2009-10-05 Thread n00m
In my early teen, school years "Let It Be" by The Beatles sounded for my ears (incredibly clearly and obviously!) as "Lia Ri Pip". In school I studied French, English only many years later. My inner translation of "Here you are!" is smth like "Catch it!", "Take it!", "Look at this!" etc -- http:/

Re: How to sort a list of strings on a substring

2009-10-05 Thread Steven D'Aprano
On Mon, 05 Oct 2009 21:16:38 -0700, n00m wrote: > English language is not my mother toung, so I can't grasp many subtle > nuances of it. Maybe "here you are" means to me quite a different thing > than to you. It means "here is the thing you were looking for". Anyway, nothing I wrote was meant as

Re: How to sort a list of strings on a substring

2009-10-05 Thread alex23
Steven D'Aprano wrote: > Oh please. That's a ridiculous excuse. Your post started with "Here you > are" -- the implication is that you thought it *was* a solution, not a > hint. A hint would be something like "Write a key function, perhaps using > lambda, and pass it to the sort() method using the

Re: How to sort a list of strings on a substring

2009-10-05 Thread Scott
On Oct 5, 6:05 pm, MRAB wrote: > Scott wrote: > > I create a list of logs called LogList. Here is a sample: > > > LogList = > > ["inbound tcp office 192.168.0.125 inside 10.1.0.91 88", > > "inbound tcp office 192.168.0.220 inside 10.1.0.31 2967", > > "inbound udp lab 172.24.0.110 inside 10.1.0.6 1

Re: How to sort a list of strings on a substring

2009-10-05 Thread n00m
English language is not my mother toung, so I can't grasp many subtle nuances of it. Maybe "here you are" means to me quite a different thing than to you. -- http://mail.python.org/mailman/listinfo/python-list

Re: How to sort a list of strings on a substring

2009-10-05 Thread Steven D'Aprano
On Mon, 05 Oct 2009 20:33:51 -0700, n00m wrote: >> No, that's incorrect. Try it with this data and you will see it fails: > > Of course, you are right, but I think the topic-starter is smart enough > to understand that I suggested only a hint, a sketch, a sample of how to > use "key=" with "lambd

Re: How to sort a list of strings on a substring

2009-10-05 Thread n00m
> No, that's incorrect. Try it with this data and you will see it fails: Of course, you are right, but I think the topic-starter is smart enough to understand that I suggested only a hint, a sketch, a sample of how to use "key=" with "lambda", not a ready-to-apply solution. -- http://mail.python.

Re: How to sort a list of strings on a substring

2009-10-05 Thread Steven D'Aprano
On Mon, 05 Oct 2009 15:45:58 -0700, n00m wrote: > Here you are: > > LogList = [\ > "inbound tcp office 192.168.0.125 inside 10.1.0.91 88", "inbound tcp > office 192.168.0.220 inside 10.1.0.31 2967", "inbound udp lab > 172.24.0.110 inside 10.1.0.6 161", "inbound udp office 192.168.0.22

Re: How to sort a list of strings on a substring

2009-10-05 Thread MRAB
Scott wrote: I create a list of logs called LogList. Here is a sample: LogList = ["inbound tcp office 192.168.0.125 inside 10.1.0.91 88", "inbound tcp office 192.168.0.220 inside 10.1.0.31 2967", "inbound udp lab 172.24.0.110 inside 10.1.0.6 161", "inbound udp office 192.168.0.220 inside 10.1.0.

How to sort a list of strings on a substring

2009-10-05 Thread Scott
I create a list of logs called LogList. Here is a sample: LogList = ["inbound tcp office 192.168.0.125 inside 10.1.0.91 88", "inbound tcp office 192.168.0.220 inside 10.1.0.31 2967", "inbound udp lab 172.24.0.110 inside 10.1.0.6 161", "inbound udp office 192.168.0.220 inside 10.1.0.13 53"] I want

RE: How to sort a list of file paths

2008-12-02 Thread Eriksson, John
","File1.txt","File10.txt"] file_list.sort(key=ALPHANUM_KEY) # --- Best Regards /John -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris Rebert Sent: den 2 december 2008 10:26 To: Eriksson, John Cc: python-list@

Re: How to sort a list of file paths

2008-12-02 Thread Chris Rebert
On Tue, Dec 2, 2008 at 12:36 AM, Eriksson, John <[EMAIL PROTECTED]> wrote: > Hi, > > > > This weekend I had some problems to get a list containing file paths to be > sorted in a way that I could use. > > > > I also found a thread in this mailing list ( > http://mail.python.org/pipermail/python-list

Re: How to sort a list of file paths

2008-12-02 Thread James Mills
Hi Eriksson, It's nice to see people actually contribute what they've learned back to the community. Great problem, well thought out solution and congrats on the learning :) I can't say per say that I've actually run into a situation where I need to sort file paths in this way ... But if I do I'l

How to sort a list of file paths

2008-12-02 Thread Eriksson, John
Hi, This weekend I had some problems to get a list containing file paths to be sorted in a way that I could use. I also found a thread in this mailing list ( http://mail.python.org/pipermail/python-list/2007-April/433590.html ) and realized that others might be interested in a solution. So...

Re: Is there an easy way to sort a list by two criteria?

2008-02-11 Thread thebjorn
On Feb 11, 10:47 am, [EMAIL PROTECTED] wrote: [...] > A little known thing from Python 2.5: [...] > >>> sorted(lst, key=itemgetter(2, 1)) Cute, thanks :-) --bjorn -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there an easy way to sort a list by two criteria?

2008-02-11 Thread bearophileHUGS
[repost] Duncan Booth: > >>> from operator import itemgetter > >>> lst = [(1,2,4),(3,2,1),(2,2,2),(2,1,4),(2,4,1)] > >>> lst.sort(key=itemgetter(1)) > >>> lst.sort(key=itemgetter(2)) > >>> lst > [(3, 2, 1), (2, 4, 1), (2, 2, 2), (2, 1, 4), (1, 2, 4)] A little known thing from Python 2.5: >>> fro

Re: Is there an easy way to sort a list by two criteria?

2008-02-10 Thread neocortex
Hello! Thank you all, so much! Now I can do double-criteria sort in at least three ways. More than I have expected. Best, PM -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there an easy way to sort a list by two criteria?

2008-02-09 Thread Duncan Booth
thebjorn <[EMAIL PROTECTED]> wrote: > I'm not sure which Python is default for Ubuntu 6.06, but assuming you > can access a recent one (2.4), the list.sort() function takes a key > argument (that seems to be rather sparsely documented in the tutorial > and the docstring...). E.g.: > lst = [(

Re: Is there an easy way to sort a list by two criteria?

2008-02-09 Thread thebjorn
On Feb 10, 3:05 am, neocortex <[EMAIL PROTECTED]> wrote: > Hello! > I am a newbie in Python. Recently, I get stuck with the problem of > sorting by two criteria. In brief, I have a two-dimensional list (for > a table or a matrix). Now, I need to sort by two columns, but I cannot > figure out how to

Re: Is there an easy way to sort a list by two criteria?

2008-02-09 Thread Steven D'Aprano
On Sat, 09 Feb 2008 18:05:14 -0800, neocortex wrote: > Hello! > I am a newbie in Python. Recently, I get stuck with the problem of > sorting by two criteria. In brief, I have a two-dimensional list (for a > table or a matrix). Now, I need to sort by two columns, but I cannot > figure out how to do

Re: Is there an easy way to sort a list by two criteria?

2008-02-09 Thread Steve Holden
neocortex wrote: > Hello! > I am a newbie in Python. Recently, I get stuck with the problem of > sorting by two criteria. In brief, I have a two-dimensional list (for > a table or a matrix). Now, I need to sort by two columns, but I cannot > figure out how to do that. I read somewhere that it is po

Re: Is there an easy way to sort a list by two criteria?

2008-02-09 Thread Jeff Schwab
neocortex wrote: > Hello! > I am a newbie in Python. Recently, I get stuck with the problem of > sorting by two criteria. In brief, I have a two-dimensional list (for > a table or a matrix). Now, I need to sort by two columns, but I cannot > figure out how to do that. I read somewhere that it is po

Is there an easy way to sort a list by two criteria?

2008-02-09 Thread neocortex
Hello! I am a newbie in Python. Recently, I get stuck with the problem of sorting by two criteria. In brief, I have a two-dimensional list (for a table or a matrix). Now, I need to sort by two columns, but I cannot figure out how to do that. I read somewhere that it is possible to do: >>> table.sor

Re: about sort a list with integer key

2008-01-13 Thread lotrpy
On 1月13日, 下午8时32分, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Use lambda when it works better for you, the speed difference is > marginal in practice anyway. itemgetter is not (and was never > intended to be) a general substitute for functions, as you've > discovered. > > The marginal speed differ

Re: about sort a list with integer key

2008-01-13 Thread Hrvoje Niksic
lotrpy <[EMAIL PROTECTED]> writes: > if i want sort each line by the first part,(it's a integer, in fact). > don't know how to do it with itemgetter. > key = int(itemgetter(0)) is wrong, key = lambda x:int(x[0]) works. > but s.b. told me itemgetter execute more quickly . Use lambda when it works

Re: about sort a list with integer key

2008-01-13 Thread Fredrik Lundh
lotrpy wrote: > key = int(itemgetter(0)) is wrong, key = lambda x:int(x[0]) works. > but s.b. told me itemgetter execute more quickly . so you're more interested in speed than in correctness? ;-) operator.itemgetter is a function factory that creates a *function* that fetches the given item fr

about sort a list with integer key

2008-01-13 Thread lotrpy
hi, if I want sort each line ,by the last part,of a file, below is the source. from operator import itemgetter content = (line.split() for line in file('foo.txt', 'rb')) for cursor, line in enumerate(sorted(content, key = itemgetter(-1), reverse = True)): print cursor, ' '.join(line) the conten

Re: sort a list

2007-10-27 Thread Diez B. Roggisch
[EMAIL PROTECTED] schrieb: > hello, > > I'm new to python and this list.I hope this question don't repeat an old > story on the list. > > I have a number list,say it's [3,2,1,4,5],I want to sort it as > [1,2,3,4,5],how to do? your_list.sort() Please read the documentation, all of this is prop

sort a list

2007-10-27 Thread _nospamnet_
hello, I'm new to python and this list.I hope this question don't repeat an old story on the list. I have a number list,say it's [3,2,1,4,5],I want to sort it as [1,2,3,4,5],how to do? Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Re: Using s.sort([cmp[, key[, reverse]]]) to sort a list of objects based on a attribute

2007-09-10 Thread Stefan Arentz
[EMAIL PROTECTED] (Alex Martelli) writes: > Stefan Arentz <[EMAIL PROTECTED]> wrote: > > > Miki <[EMAIL PROTECTED]> writes: > > > > > > steps.sort(key = lambda s: s.time) > > > This is why attrgetter in the operator module was invented. > > > from operator import attrgetter > > > ... > > > ste

Re: Using s.sort([cmp[, key[, reverse]]]) to sort a list of objects based on a attribute

2007-09-09 Thread Alex Martelli
Stefan Arentz <[EMAIL PROTECTED]> wrote: > Miki <[EMAIL PROTECTED]> writes: > > > > steps.sort(key = lambda s: s.time) > > This is why attrgetter in the operator module was invented. > > from operator import attrgetter > > ... > > steps.sort(key=attrgettr("time")) > > Personally I prefer the a

Re: Using s.sort([cmp[, key[, reverse]]]) to sort a list of objects based on a attribute

2007-09-09 Thread Stefan Arentz
Miki <[EMAIL PROTECTED]> writes: > > steps.sort(key = lambda s: s.time) > This is why attrgetter in the operator module was invented. > from operator import attrgetter > ... > steps.sort(key=attrgettr("time")) Personally I prefer the anonymous function over attrgettr :) S. -- http://mail.pyt

Re: Using s.sort([cmp[, key[, reverse]]]) to sort a list of objects based on a attribute

2007-09-08 Thread Miki
> steps.sort(key = lambda s: s.time) This is why attrgetter in the operator module was invented. from operator import attrgetter ... steps.sort(key=attrgettr("time")) HTH, -- Miki <[EMAIL PROTECTED]> http://pythonwise.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list

Re: Using s.sort([cmp[, key[, reverse]]]) to sort a list of objects based on a attribute

2007-09-07 Thread Marc 'BlackJack' Rintsch
On Fri, 07 Sep 2007 06:57:35 -0700, cjt22 wrote: > I have a step class and store in a list step instances > A step instance contains variables: name, startTime etc and startTime > is stored as a string %H:%M:%S > > What I would like to do is to be able to sort this list of objects > based on the

Re: Using s.sort([cmp[, key[, reverse]]]) to sort a list of objects based on a attribute

2007-09-07 Thread Stefan Arentz
[EMAIL PROTECTED] writes: > Hi there > > I am fairly new to Python and have not really used regular expressions > before (I think this might be needed for my query) and wondered if you > could help > > I have a step class and store in a list step instances > A step instance contains variables: n

Re: Using s.sort([cmp[, key[, reverse]]]) to sort a list of objects based on a attribute

2007-09-07 Thread Tim Golden
[EMAIL PROTECTED] wrote: > Hi there > > I am fairly new to Python and have not really used regular expressions > before (I think this might be needed for my query) and wondered if you > could help > > I have a step class and store in a list step instances > A step instance contains variables: nam

Using s.sort([cmp[, key[, reverse]]]) to sort a list of objects based on a attribute

2007-09-07 Thread cjt22
Hi there I am fairly new to Python and have not really used regular expressions before (I think this might be needed for my query) and wondered if you could help I have a step class and store in a list step instances A step instance contains variables: name, startTime etc and startTime is stored

Re: sort a list of files

2006-05-06 Thread Scott David Daniels
Ryan Forsythe wrote: > Gary Wessle wrote: >> Hi >> >> I am trying to print out the contents of a directory, sorted. > ... >> if I remove ".sort()" at the end of line 6 I get an unsorted list of >> files, if I leave it I get None. who do I fix this? > > `blah.sort()` sorts in-place and returns None

Re: sort a list of files

2006-05-06 Thread Ryan Forsythe
Gary Wessle wrote: > Hi > > I am trying to print out the contents of a directory, sorted. ... > if I remove ".sort()" at the end of line 6 I get an unsorted list of > files, if I leave it I get None. who do I fix this? `blah.sort()` sorts in-place and returns None. You probably want sorted(blah)

sort a list of files

2006-05-06 Thread Gary Wessle
Hi I am trying to print out the contents of a directory, sorted. the code 1 import os, sys 2 3 if len(sys.argv) < 2: 4 sys.exit("please enter a suitable directory.") 5 6 print os.listdir(sys.argv[1]).sort() **