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
;>
> >>>
> >>> 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
>
> > > >>> 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 1
> > >>> elif abs(lo1[1] - lo2[1]) == 1 and lo1[0] == lo2[0]:
> > >>> return 1
> > >>> else:
> > >>> return 0
> > >>>
> > >>>
> > >>> sorted(testing1,
;>> 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]))
> >>>
> >
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
>
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
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
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
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
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
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
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
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
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
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
> 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
> 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
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
> 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
> 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
> 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
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
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
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
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
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
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
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
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
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
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
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
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
> 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
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
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
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. :
> 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
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
> 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
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
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.
>
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,
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
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
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
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
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.
, 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'
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
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
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
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.
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:/
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
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
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
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
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
> 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.
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
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.
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
","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@
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
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
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...
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
[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
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
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 = [(
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
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
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
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
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
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
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
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
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
[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
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
[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
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
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
> 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
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
[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
[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
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
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
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)
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()
**
94 matches
Mail list logo