On Tuesday, January 31, 2017 at 12:34:38 PM UTC-8, MRAB wrote:
> On 2017-01-31 20:26, Larry Martell wrote:
> The module 'datetime' contains a class called 'datetime'. Judging by
> your exception, 'datetime' is the module.
>
> Try "datetime.datetime.strptime" instead.
This re-use of the name "da
On Tue, Jan 31, 2017 at 3:30 PM, Chris Angelico wrote:
> On Wed, Feb 1, 2017 at 7:26 AM, Larry Martell wrote:
>> I have a list of dicts and one item of the dict is a date in m/d/Y
>> format. I want to sort by that. I tried this:
>>
>> sorted(data['trends'], key=lambda k:
>> datetime.strptime(k['d
On 01/31/2017 01:26 PM, Larry Martell wrote:
> I have a list of dicts and one item of the dict is a date in m/d/Y
> format. I want to sort by that. I tried this:
>
> sorted(data['trends'], key=lambda k:
> datetime.strptime(k['date_time'],'%m/%d/%Y'))
>
> But that fails with:
>
> Exception Type:
On 2017-01-31 20:26, Larry Martell wrote:
I have a list of dicts and one item of the dict is a date in m/d/Y
format. I want to sort by that. I tried this:
sorted(data['trends'], key=lambda k:
datetime.strptime(k['date_time'],'%m/%d/%Y'))
But that fails with:
Exception Type: AttributeError at /
Larry Martell wrote:
> I have a list of dicts and one item of the dict is a date in m/d/Y
> format. I want to sort by that. I tried this:
>
> sorted(data['trends'], key=lambda k:
> datetime.strptime(k['date_time'],'%m/%d/%Y'))
>
> But that fails with:
>
> Exception Type: AttributeError at
> /re
On Wed, Feb 1, 2017 at 7:26 AM, Larry Martell wrote:
> I have a list of dicts and one item of the dict is a date in m/d/Y
> format. I want to sort by that. I tried this:
>
> sorted(data['trends'], key=lambda k:
> datetime.strptime(k['date_time'],'%m/%d/%Y'))
>
> But that fails with:
>
> Exception
I have a list of dicts and one item of the dict is a date in m/d/Y
format. I want to sort by that. I tried this:
sorted(data['trends'], key=lambda k:
datetime.strptime(k['date_time'],'%m/%d/%Y'))
But that fails with:
Exception Type: AttributeError at /report/CDSEM/WaferAlignment/ajax/waChart.jso
Random832 wrote:
> On Mon, Apr 4, 2016, at 02:56, Peter Otten wrote:
>> > That works well. Why is it 'cheating'?
>>
>> On second thought it isn't ;)
>
> It does require a numeric type, though. There are lots of types that are
> orderable but do not have a negation operator that provides a key w
On Mon, Apr 4, 2016, at 02:56, Peter Otten wrote:
> > That works well. Why is it 'cheating'?
>
> On second thought it isn't ;)
It does require a numeric type, though. There are lots of types that are
orderable but do not have a negation operator that provides a key with
reversed ordering.
--
ht
DFS wrote:
> On 4/3/2016 3:31 PM, Peter Otten wrote:
> from operator import itemgetter as get
> print "\n".join("{1} {0}".format(*p) for p in sorted(
>> ... sorted(colCounts, key=get(1)), key=get(0), reverse=True))
>
> Kind of clunky looking. Is that why don't you recommend it?
That, a
On 4/3/2016 3:31 PM, Peter Otten wrote:
DFS wrote:
cntText = 60
cntBool = 20
cntNbrs = 30
cntDate = 20
cntBins = 20
strText = " text: "
strBool = " boolean: "
strNbrs = " numeric: "
strDate = " date-time:"
strBins = " binary: "
colCounts = [(cntText,strText) , (cntBool,strBool),
DFS wrote:
> cntText = 60
> cntBool = 20
> cntNbrs = 30
> cntDate = 20
> cntBins = 20
>
> strText = " text: "
> strBool = " boolean: "
> strNbrs = " numeric: "
> strDate = " date-time:"
> strBins = " binary: "
>
> colCounts = [(cntText,strText) , (cntBool,strBool), (cntNbrs,strNbrs)
cntText = 60
cntBool = 20
cntNbrs = 30
cntDate = 20
cntBins = 20
strText = " text: "
strBool = " boolean: "
strNbrs = " numeric: "
strDate = " date-time:"
strBins = " binary: "
colCounts = [(cntText,strText) , (cntBool,strBool), (cntNbrs,strNbrs) ,
(cntDate,strDate) , (cntBins,strB
On 4/3/2016 2:30 PM, DFS wrote:
cntText = 60
cntBool = 20
cntNbrs = 30
cntDate = 20
cntBins = 20
strText = " text: "
strBool = " boolean: "
strNbrs = " numeric: "
strDate = " date-time:"
strBins = " binary: "
colCounts = [(cntText,strText) , (cntBool,strBool), (cntNbrs,strNbrs) ,
(
On Jul 22, 12:56 pm, Thomas Jollans wrote:
> On 07/21/2010 03:38 PM, kak...@gmail.com wrote:
>
>
>
> > On Jul 21, 9:04 am, "kak...@gmail.com" wrote:
> >> On Jul 21, 8:58 am, Stefan Behnel wrote:
>
> >>> kak...@gmail.com, 21.07.2010 14:36:
>
> From the subject of my message it's clear that i
On 07/21/2010 03:38 PM, kak...@gmail.com wrote:
> On Jul 21, 9:04 am, "kak...@gmail.com" wrote:
>> On Jul 21, 8:58 am, Stefan Behnel wrote:
>>
>>
>>
>>> kak...@gmail.com, 21.07.2010 14:36:
>>
From the subject of my message it's clear that i get an xml message
from a socket,
>>
>>> Not a
kak...@gmail.com, 21.07.2010 15:38:
On Jul 21, 9:04 am, "kak...@gmail.com" wrote:
On Jul 21, 8:58 am, Stefan Behnel wrote:
kak...@gmail.com, 21.07.2010 14:36:
From the subject of my message it's clear that i get an xml message
from a socket,
Not at all, but now that you say it...
On Jul 21, 9:04 am, "kak...@gmail.com" wrote:
> On Jul 21, 8:58 am, Stefan Behnel wrote:
>
>
>
> > kak...@gmail.com, 21.07.2010 14:36:
>
> > > From the subject of my message it's clear that i get an xml message
> > > from a socket,
>
> > Not at all, but now that you say it...
>
> > > i parse it a
On Jul 21, 8:58 am, Stefan Behnel wrote:
> kak...@gmail.com, 21.07.2010 14:36:
>
> > From the subject of my message it's clear that i get an xml message
> > from a socket,
>
> Not at all, but now that you say it...
>
>
>
> > i parse it and the result is a list like the one that
> > follows:
> > ID
kak...@gmail.com, 21.07.2010 14:36:
From the subject of my message it's clear that i get an xml message
from a socket,
Not at all, but now that you say it...
i parse it and the result is a list like the one that
follows:
ID_Col
4 Serverak ip OFFLINE
29
Hi pythonistas,
>From the subject of my message it's clear that i get an xml message
from a socket, i parse it and the result is a list like the one that
follows:
ID_Col
4 Serverak ip OFFLINE
29 Server and2ip OFFLINE
5 Proxy l34e
MRAB wrote:
You'd have to post an example of that, but you could try deleting some
of the entries before sorting so see whether you can still reproduce the
problem with a smaller list.
John Posner wrote:
Please cut-and-paste the exact error message (or other evidence of
"failure") into a mess
On 2/12/2010 12:45 PM, R (Chandra) Chandrasekhar wrote:
Dear Folks,
I have lines of values like so:
14, [25, 105, 104]
10, [107, 106, 162]
21, [26, 116, 165]
I need to sort them in two ways:
(a) By the numeric value of the first column; and
(b) by the sum of the elements of the second item i
R (Chandra) Chandrasekhar wrote:
Dear Folks,
I have lines of values like so:
14, [25, 105, 104]
10, [107, 106, 162]
21, [26, 116, 165]
I need to sort them in two ways:
(a) By the numeric value of the first column; and
(b) by the sum of the elements of the second item in each list, which is
Dear Folks,
I have lines of values like so:
14, [25, 105, 104]
10, [107, 106, 162]
21, [26, 116, 165]
I need to sort them in two ways:
(a) By the numeric value of the first column; and
(b) by the sum of the elements of the second item in each list, which is
a list in itself.
At present, I
Ben Finney wrote:
> Peter Otten <__pete...@web.de> writes:
>
>> I can't find the relevant part of the 2.6 documentation, but something
>> like
>>
>> >>> def key(x):
>> ... t = type(x)
>> ... t = compat.get(t, t)
>> ... return t.__name__, id(t), x
>> ...
>> >>> compat = {bool: float, i
Terry Reedy writes:
> And complex numbers, and probably some other things, cannot be sorted
> even in Python2. Universal sorting is a broken idea, so Python3 leaves
> it to you to say what *you* mean.
Okay. I guess I'd better figure out what that is, for this code base,
before porting it to Pyth
On 1/28/2010 8:24 PM, Steven D'Aprano wrote:
Um, what ordering do you want?
The same ordering I'd get in Python 2; that is, determined by the types
of the elements.
The ordering has not been consistent across minor versions of Python 2:
And complex numbers, and probably some other things,
On Fri, 29 Jan 2010 12:13:50 +1100, Ben Finney wrote:
> Paul Rubin writes:
>
>> Ben Finney writes:
>> > So how should I be sorting a list with entries of “unequal types”
>> > such that it will work in Python 3?
>>
>> Um, what ordering do you want?
Paul Rubin writes:
> Ben Finney writes:
> > So how should I be sorting a list with entries of “unequal types”
> > such that it will work in Python 3?
>
> Um, what ordering do you want?
The same ordering I'd get in Python 2; that is, determined by the types
of t
On Fri, 29 Jan 2010 11:01:21 +1100, Ben Finney wrote:
> So how should I be sorting a list with entries of “unequal types” such
> that it will work in Python 3?
That depends on how you want the items to be sorted. Python 2.x sorted
unequal types in some arbitrary but consistent order. If
Paul Rubin wrote:
Ben Finney writes:
So how should I be sorting a list with entries of “unequal types” such
that it will work in Python 3?
Um, what ordering do you want? Basically you have to write a custom key
function (they removed the option of writing a comparison function).
Maybe
Ben Finney wrote:
Howdy all,
Python 2.6 tells me that, in Python 3, sorting a list with entries of
incompatible types is not allowed:
=
$ python2.5 -c "foo = [1, True, 'green', 4, -27, 15.3]; foo.sort(); print foo;"
[-27, 1, True, 4, 15.301, 'green
Ben Finney writes:
> So how should I be sorting a list with entries of “unequal types” such
> that it will work in Python 3?
Um, what ordering do you want? Basically you have to write a custom key
function (they removed the option of writing a comparison function).
Maybe somethin
Ben Finney wrote:
> Python 2.6 tells me that, in Python 3, sorting a list with entries of
> incompatible types is not allowed:
> $ python2.6 -3 -c "foo = [1, True, 'green', 4, -27, 15.3]; foo.sort();
> print foo;" -c:1: DeprecationWarning: comparing unequal types
Howdy all,
Python 2.6 tells me that, in Python 3, sorting a list with entries of
incompatible types is not allowed:
=
$ python2.5 -c "foo = [1, True, 'green', 4, -27, 15.3]; foo.sort(); print foo;"
[-27, 1, True, 4, 15.301, 'green']
$ python2.6
On Feb 6, 2:41 pm, Stephen Hansen wrote:
> > I think there may have been a misunderstanding. I was already using
> > attrgetter, my problem is that it doesn't appear to be sorting by the
> > argument i give it. How does sort work with strings? How about with
> > datetime.time or datetime.date?
> I think there may have been a misunderstanding. I was already using
> attrgetter, my problem is that it doesn't appear to be sorting by the
> argument i give it. How does sort work with strings? How about with
> datetime.time or datetime.date?
You were using the attrgetter, but it looks like
On Feb 6, 2:34 pm, Robocop wrote:
> On Feb 6, 2:20 pm, Robocop wrote:
>
>
>
> > On Feb 6, 2:17 pm, Robocop wrote:
>
> > > On Feb 6, 1:03 pm, bearophileh...@lycos.com wrote:
>
> > > > Robocop:
>
> > > > >then within each department block of the list, have it organized by
> > > > >projects.<
>
>
Robocop wrote:
UH OH GUYS!
line 110, in sorter
timesheets.sort(key=attrgetter("department", "engagement",
"date","start"))
TypeError: attrgetter expected 1 arguments, got 4
Um... what version of Python are you running? Alway specify. (Too many
people do not). In 3.0
from operator imp
On Feb 6, 2:20 pm, Robocop wrote:
> On Feb 6, 2:17 pm, Robocop wrote:
>
>
>
> > On Feb 6, 1:03 pm, bearophileh...@lycos.com wrote:
>
> > > Robocop:
>
> > > >then within each department block of the list, have it organized by
> > > >projects.<
>
> > > I don't know what does it means.
>
> > > > ti
On Feb 6, 2:17 pm, Robocop wrote:
> On Feb 6, 1:03 pm, bearophileh...@lycos.com wrote:
>
>
>
> > Robocop:
>
> > >then within each department block of the list, have it organized by
> > >projects.<
>
> > I don't know what does it means.
>
> > > timesheets.sort(key=operator.attrgetter('string'))
>
On Feb 6, 1:03 pm, bearophileh...@lycos.com wrote:
> Robocop:
>
> >then within each department block of the list, have it organized by
> >projects.<
>
> I don't know what does it means.
>
> > timesheets.sort(key=operator.attrgetter('string'))
>
> Try something like:
> timesheets.sort(key=attrgette
On Feb 6, 1:03 pm, bearophileh...@lycos.com wrote:
> Robocop:
>
> >then within each department block of the list, have it organized by
> >projects.<
>
> I don't know what does it means.
>
> > timesheets.sort(key=operator.attrgetter('string'))
>
> Try something like:
> timesheets.sort(key=attrgette
Robocop:
>then within each department block of the list, have it organized by projects.<
I don't know what does it means.
> timesheets.sort(key=operator.attrgetter('string'))
Try something like:
timesheets.sort(key=attrgetter("department", "engagement", "date",
"stare_hour"))
> My brain might
> I've found myself stumped when trying to organize this list of
> objects. The objects in question are timesheets which i'd like to
> sort by four attributes:
>
> class TimeSheet:
> department = string
> engagement = string
> date = datetime.date
> stare_hour = datetime.time
>
> My ultim
Quoth Robocop :
> Hello again,
> I've found myself stumped when trying to organize this list of
> objects. The objects in question are timesheets which i'd like to
> sort by four attributes:
>
> class TimeSheet:
> department = string
> engagement = string
> date = datetime.date
> stare_ho
Hello again,
I've found myself stumped when trying to organize this list of
objects. The objects in question are timesheets which i'd like to
sort by four attributes:
class TimeSheet:
department = string
engagement = string
date = datetime.date
stare_hour = datetime.time
My ultimate goal
RC wrote:
> unsortedList = list(["XYZ","ABC"])
>
> sortedList = unsortedList.sort()
> print sortedList
>
>
> Why this return None?
Because the sort method sorts the list in place (and returns None).
> How do I get return as ["ABC", "XYZ"]?
>>> unsortedList = ["XYZ","ABC"]
>>> unsortedList.sor
On Oct 28, 2008, at 9:45 , RC wrote:
unsortedList = list(["XYZ","ABC"])
sortedList = unsortedList.sort()
print sortedList
the sort method is in-place, so it modifies the object which calls
it, and doesn't return anything:
In [1]:unsortedList = list(["XYZ","ABC"])
In [2]:sortedList = uns
To expand on Tino's response, sort() sorts in place and does not *return* a
sorted copy of the list.
In other words:
unsortedList = list(["XYZ","ABC"])
unsortedList.sort()
print sortedList
is correct. Since sort() returns None, you lose your list if you do:
unsortedList = unsortedList.sort()
RC wrote:
> unsortedList = list(["XYZ","ABC"])
>
> sortedList = unsortedList.sort()
> print sortedList
>
>
> Why this return None?
> How do I get return as ["ABC", "XYZ"]?
The list's .sort method returns None because it modifies the list
in-place, so after the call it is sorted. So you can eith
RC wrote:
unsortedList = list(["XYZ","ABC"])
sortedList = unsortedList.sort()
print sortedList
Why this return None?
Because you did not read the documentation.
Regards
Tino
smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list
unsortedList = list(["XYZ","ABC"])
sortedList = unsortedList.sort()
print sortedList
Why this return None?
How do I get return as ["ABC", "XYZ"]?
--
http://mail.python.org/mailman/listinfo/python-list
Thanks so much everyone! That works great, & (presumably) is way
faster than the way I was doing it--
--
http://mail.python.org/mailman/listinfo/python-list
Paddy wrote:
> On Apr 9, 4:04 am, Jason <[EMAIL PROTECTED]> wrote:
>> Hi folks--
>>
>> Basically, I have a pressing need for a combination of 5.2 "Sorting a
>> List of Strings Case-Insensitively" & 5.3 "Sorting a List of Objects
>>
On Apr 9, 4:04 am, Jason <[EMAIL PROTECTED]> wrote:
> Hi folks--
>
> Basically, I have a pressing need for a combination of 5.2 "Sorting a
> List of Strings Case-Insensitively" & 5.3 "Sorting a List of Objects
> by an Attribute of the Objects" from
On Apr 8, 8:26 pm, "David Harrison" <[EMAIL PROTECTED]> wrote:
> On 09/04/2008, Jason <[EMAIL PROTECTED]> wrote:
>
> > Hi folks--
>
> > Basically, I have a pressing need for a combination of 5.2 "Sorting a
> > List of Strings Case-Inse
On 09/04/2008, Jason <[EMAIL PROTECTED]> wrote:
> Hi folks--
>
> Basically, I have a pressing need for a combination of 5.2 "Sorting a
> List of Strings Case-Insensitively" & 5.3 "Sorting a List of Objects
> by an Attribute of the Objects" from t
Hi folks--
Basically, I have a pressing need for a combination of 5.2 "Sorting a
List of Strings Case-Insensitively" & 5.3 "Sorting a List of Objects
by an Attribute of the Objects" from the Python Cookbook.
My first guess isn't working:
import operator
def sort
Steven D'Aprano wrote:
>> The following relies on undocumented (I hope) behaviour:
> preferences = [10, 30, 20]
> hosts = [ "mx1.domain.com", "anotherhost.domain.com",
>>... "mx2.domain.com"]
> hosts.sort(key=lambda x, p=iter(preferences).next: p())
> preferences.sort()
> ho
On Mon, 21 Jan 2008 09:53:10 +0100, Peter Otten wrote:
> Santiago Romero wrote:
>
>> I'm trying to sort both lists so that they end like this:
>>
>> preferences = [10, 20, 30]
>> hosts = [ "mx1.domain.com", "mx2.domain.com", "anotherhost.domain.com"
>> ]
>>
>> I want to sort hosts list depen
On Mon, 21 Jan 2008 17:32:42 +0800, J. Peng wrote:
> Steven D'Aprano 写道:
>> On Mon, 21 Jan 2008 16:23:50 +0800, J. Peng wrote:
>>
>>> J. Peng 写道:
>>>
k = (i.split())[3]
y = (i.split())[1]
>>> btw, why can't I write the above two into one statement?
>>>
>>> (k,y) = (i.split())[3,1]
Thanks all for the answers ... I'll use a tuple as you said :)
Anyway, is interesting to know how to sort 2 lists when you dont want
to use tuples, so thanks also to Peter :)
> Then one have to split the list twice.Given the list is large,it's maybe
> not good for performance.Is it a more effe
Steven D'Aprano 写道:
> On Mon, 21 Jan 2008 16:23:50 +0800, J. Peng wrote:
>
>> J. Peng 写道:
>>
>>>k = (i.split())[3]
>>>y = (i.split())[1]
>> btw, why can't I write the above two into one statement?
>>
>> (k,y) = (i.split())[3,1]
>
> I don't know. What's "i"?
>
> I'm guessing "i" is a stri
On Mon, 21 Jan 2008 16:23:50 +0800, J. Peng wrote:
> J. Peng 写道:
>
>>k = (i.split())[3]
>>y = (i.split())[1]
>
> btw, why can't I write the above two into one statement?
>
> (k,y) = (i.split())[3,1]
I don't know. What's "i"?
I'm guessing "i" is a string (and what a horrible choice of
Santiago Romero wrote:
> I'm trying to sort both lists so that they end like this:
>
> preferences = [10, 20, 30]
> hosts = [ "mx1.domain.com", "mx2.domain.com",
> "anotherhost.domain.com" ]
>
> I want to sort hosts list depending on the numeric order of
> "preferences".
The following relies
J. Peng 写道:
>k = (i.split())[3]
>y = (i.split())[1]
btw, why can't I write the above two into one statement?
(k,y) = (i.split())[3,1]
--
http://mail.python.org/mailman/listinfo/python-list
I tried to write it below,it can work,:)
v= """preference 10 host mx1.domain.com
preference 30 host anotherhost.domain.com
preference 20 host mx2.domain.com"""
x=v.split("\n")
li =[]
for i in x:
k = (i.split())[3]
y = (i.split())[1]
li.append((y,k))
li.sort()
print li
the output is:
On 21 ene, 08:41, Santiago Romero <[EMAIL PROTECTED]> wrote:
> Hi ...
>
> I have the following DNS MX records info:
>
> domain.com
> preference 10 host mx1.domain.com
> preference 30 host anotherhost.domain.com
> preference 20 host mx2.domain.com
> And finally ... do you think there is a bette
Hi ...
I have the following DNS MX records info:
domain.com
preference 10 host mx1.domain.com
preference 30 host anotherhost.domain.com
preference 20 host mx2.domain.com
I'm storing this info in 2 lists:
preferences = [10, 30, 20]
hosts = [ "mx1.domain.com", "anotherhost.domain.com",
"mx2.d
On 29 nov, 04:11, Hrvoje Niksic <[EMAIL PROTECTED]> wrote:
> Stef Mientki <[EMAIL PROTECTED]> writes:
> > although I find it rather non-intuitive.
> > I didn't expect a copy, but a reference to itself wouldn't be asked
> > too much ?
>
> If you didn't expect a copy, why rely on the return value? Y
Hrvoje Niksic wrote:
> Stef Mientki <[EMAIL PROTECTED]> writes:
>
>> although I find it rather non-intuitive.
>> I didn't expect a copy, but a reference to itself wouldn't be asked
>> too much ?
>
> If you didn't expect a copy, why rely on the return value? You could
> simply continue using the
Stef Mientki <[EMAIL PROTECTED]> writes:
> although I find it rather non-intuitive.
> I didn't expect a copy, but a reference to itself wouldn't be asked
> too much ?
If you didn't expect a copy, why rely on the return value? You could
simply continue using the sorted list. Your first post says
On Nov 29, 10:40 am, Stef Mientki <[EMAIL PROTECTED]>
wrote:
> Peter Decker wrote:
> > On Nov 28, 2007 7:22 PM, stef mientki <[EMAIL PROTECTED]> wrote:
> >> print 'xx3',ordered_list.sort()
>
> > The sort() method returns None. It sorts the list in place; it doesn't
> > return a copy of the sort
Peter Decker wrote:
> On Nov 28, 2007 7:22 PM, stef mientki <[EMAIL PROTECTED]> wrote:
>> print 'xx3',ordered_list.sort()
>
> The sort() method returns None. It sorts the list in place; it doesn't
> return a copy of the sorted list.
>
Thank you all for the answers,
I do understand now,
althou
On Nov 28, 4:22 pm, stef mientki <[EMAIL PROTECTED]> wrote:
> hello,
>
> I'm trying to sort a list, using the same list at the commandline works,
> but in a program it doesn't.
>
> Here is the code
> print 'xx1',type(ordered_list)
> print 'xx2',ordered_list
> print 'xx3',ordered_list.so
On Nov 28, 2007 7:22 PM, stef mientki <[EMAIL PROTECTED]> wrote:
> print 'xx3',ordered_list.sort()
The sort() method returns None. It sorts the list in place; it doesn't
return a copy of the sorted list.
--
# p.d.
--
http://mail.python.org/mailman/listinfo/python-list
stef mientki <[EMAIL PROTECTED]> writes:
> Here is the code
>print 'xx1',type(ordered_list)
>print 'xx2',ordered_list
>print 'xx3',ordered_list.sort()
>
> And this is the result
> xx1
> xx2 [14, 12, 10]
> xx3 None
>
> What am I doing wrong ?
Apparently, ignoring the documentation o
hello,
I'm trying to sort a list, using the same list at the commandline works,
but in a program it doesn't.
Here is the code
print 'xx1',type(ordered_list)
print 'xx2',ordered_list
print 'xx3',ordered_list.sort()
And this is the result
xx1
xx2 [14, 12, 10]
xx3 None
What am I doing
Tim Chase wrote:
>> are there available library or pythonic algorithm for sorting a list
>> of list depending on the index of the list inside the list of my
>> choice?
>
> The built-in sorted() function and the sort() method on various
> collections take an opti
> are there available library or pythonic algorithm for sorting a list
> of list depending on the index of the list inside the list of my
> choice?
The built-in sorted() function and the sort() method on various
collections take an optional "key=function" keyword paramater
with
hi,
are there available library or pythonic algorithm for sorting a list
of list depending on the index of the list inside the list of my
choice?
d_list = [
['a', 1, 9],
['b', 2, 8],
['c', 3, 7],
['d', 4, 6],
['e', 5, 5],
Hrvoje Niksic wrote:
> "Delaney, Timothy (Tim)" <[EMAIL PROTECTED]> writes:
>
>> Yep - appears I must have been misremembering from another language
>> (dunno which)
>
> Tcl
Not bloody likely - only used Tcl for expect, and then only very
minimally. I'm sure there's at least one language though
ZeD wrote:
> thebjorn wrote:
>
>> int("020")
>>> 20
>> 020
>>> 16
>>
>> You can get the latter behavior using eval:
>
> why using eval when int has the "base" optional parameter?
>
int("020")
> 20
int("020", 8)
> 16
int("09", 8)
> Traceback (most recent call last):
> F
thebjorn wrote:
>> >>> int("020")
>> 20
>> >>> 020
>> 16
>
> You can get the latter behavior using eval:
why using eval when int has the "base" optional parameter?
>>> int("020")
20
>>> int("020", 8)
16
>>> int("09", 8)
Traceback (most recent call last):
File "", line 1, in
ValueError: inval
On Sep 25, 2:45 pm, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Tue, 25 Sep 2007 12:46:54 +0800, Delaney, Timothy (Tim) wrote:
> > Carsten Haese wrote:
>
> >> On Mon, 2007-09-24 at 19:58 +0800, Delaney, Timothy (Tim) wrote:
> >>> I'm sure that in some version of Python it wou
"Delaney, Timothy (Tim)" <[EMAIL PROTECTED]> writes:
> Yep - appears I must have been misremembering from another language
> (dunno which)
Tcl
--
http://mail.python.org/mailman/listinfo/python-list
On Tue, 25 Sep 2007 12:46:54 +0800, Delaney, Timothy (Tim) wrote:
> Carsten Haese wrote:
>
>> On Mon, 2007-09-24 at 19:58 +0800, Delaney, Timothy (Tim) wrote:
>>> I'm sure that in some version of Python it would have given a
>>> ValueError (due to the default radix being 0) but it appears to have
On 9/24/07, Carsten Haese <[EMAIL PROTECTED]> wrote:
> On Mon, 2007-09-24 at 16:53 +0530, Amit Khemka wrote:
> > On 9/24/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> >
> > >>> l = ["1", "11", "2", "22"]
> > >>> sorted(l, cmp = lambda x, y: cmp(int(x), int(y))) # provide your
> > own compare
Carsten Haese wrote:
> On Mon, 2007-09-24 at 19:58 +0800, Delaney, Timothy (Tim) wrote:
>> I'm sure that in some version of Python it would have given a
>> ValueError (due to the default radix being 0) but it appears to have
>> changed to a default radix of 10 somewhere along the way.
>
> Not eve
In article <[EMAIL PROTECTED]>,
[EMAIL PROTECTED] wrote:
> hi,
>
> I have the following list -
>
> ["1", "11", "2", "22"]
>
> how do I sort it like this -
>
> ["1", "2", "11", "22"]
>
> thanks,
>
> aine
Try:
lst.sort(key = lambda s: int(s))
Assuming, of course, that "lst" is your origi
On Mon, 2007-09-24 at 19:58 +0800, Delaney, Timothy (Tim) wrote:
> I'm sure that in some version of Python it would have given a
> ValueError (due to the default radix being 0) but it appears to have
> changed to a default radix of 10 somewhere along the way.
Not even Python 1.5.2 seems to have a
aine_canby wrote:
> I have the following list -
>
> ["1", "11", "2", "22"]
>
> how do I sort it like this -
>
> ["1", "2", "11", "22"]
>>> items = ["1", "11", "2", "22"]
>>> items.sort(key=int)
>>> items
['1', '2', '11', '22']
This is more efficient than Amit's compare function and even Bruno
Carsten Haese wrote:
> That interpreter session is a work of fiction, since sorted returns
> the sorted list instead of sorting the list in place. Also, it's
> better (i.e. more readable and likely faster) to use a sort key
> function instead of a comparison function whenever possible. In this
> c
On Mon, 2007-09-24 at 16:53 +0530, Amit Khemka wrote:
> On 9/24/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> > hi,
> >
> > I have the following list -
> >
> > ["1", "11", "2", "22"]
> >
> > how do I sort it like this -
> >
> > ["1", "2", "11", "22"]
> >
>
> Hi,
>
> >>> l = ["1", "11", "2",
[EMAIL PROTECTED] a écrit :
> hi,
>
> I have the following list -
>
> ["1", "11", "2", "22"]
>
> how do I sort it like this -
>
> ["1", "2", "11", "22"]
source = ["1", "11", "2", "22"]
result = [t[1] for t in sorted((int(item), item) for item in source)]
print result
--
http://mail.python.or
On 9/24/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> hi,
>
> I have the following list -
>
> ["1", "11", "2", "22"]
>
> how do I sort it like this -
>
> ["1", "2", "11", "22"]
>
Hi,
>>> l = ["1", "11", "2", "22"]
>>> sorted(l, cmp = lambda x, y: cmp(int(x), int(y))) # provide your
own comp
hi,
I have the following list -
["1", "11", "2", "22"]
how do I sort it like this -
["1", "2", "11", "22"]
thanks,
aine
--
http://mail.python.org/mailman/listinfo/python-list
Wikipedia in Suomi lists it at the bottom ;-)
http://sv.wikipedia.org/wiki/Lista_%C3%B6ver_l%C3%A4nder#.C3.85
Cheers
~K
--
http://mail.python.org/mailman/listinfo/python-list
1 - 100 of 216 matches
Mail list logo