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
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)
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
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
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?
>
> The same ordering I'd get in Python 2; tha
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 the elements.
Peter Otten <__pete
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 that's a
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 somet
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']
$ python2.6 -c "foo = [1, T
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 something like
foo
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 not
> supported in 3.x
> [-27, 1,
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
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
>> by an Attribute of the Objects" from the Python Cookbook.
>>
>> My
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 the Python Cookbook.
>
> My first guess isn't work
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-Insensitively" & 5.3 "Sorting a List of Objects
> > by an Attribu
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 the Python Cookbook.
>
> My first guess isn't work
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
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 optional "key=function" keyword paramate
> 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 which you can pass
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
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
Thanks guys,
"dirty hack" was what I needed to get a job done quickly.
Nick
--
http://mail.python.org/mailman/listinfo/python-list
En Mon, 27 Aug 2007 15:41:15 -0300, iapain <[EMAIL PROTECTED]> escribi�:
>> Taking advantage of stable sorting is totally not a hack. The OP just
>> tried
>> the two sorting steps in the wrong order.
>
> I didnt say not to use stable sorting, but write a generic function
> and hacky code. It is
>>> records = [['dog',1,2], ['chair',2,1], ['cat',1,3], ['horse',3,4],
... ['table',3,2], ['window',3,5]]
>>> sorted(records, key = lambda x: (x[1], x[2]))
[['dog', 1, 2], ['cat', 1, 3], ['chair', 2, 1], ['table', 3, 2],
['horse', 3, 4], ['window', 3, 5]]
[EMAIL PROTECTED] wrote:
> Hi,
>
> i
On Aug 27, 2:41 pm, iapain <[EMAIL PROTECTED]> wrote:
> ... It is always better to adopt a generic approach.
The above statement is incorrect.
--
http://mail.python.org/mailman/listinfo/python-list
> Taking advantage of stable sorting is totally not a hack. The OP just tried
> the two sorting steps in the wrong order.
I didnt say not to use stable sorting, but write a generic function
and hacky code. It is always better to adopt a generic approach.
--
http://mail.python.org/mailman/listin
iapain wrote:
>> i would like to sort a list of lists. The list is first sorted on the
>> second item in the sub-lists (which I can do), then on the third item
>> (which I can't).
>
> Write a comparator instead of dirty hacks
>
> mylistoflist.sort(mycomparator)
>
> def mycomparator(a, b):
> #d
> i would like to sort a list of lists. The list is first sorted on the
> second item in the sub-lists (which I can do), then on the third item
> (which I can't).
Write a comparator instead of dirty hacks
mylistoflist.sort(mycomparator)
def mycomparator(a, b):
#do
--
http://mail.python.org/
[EMAIL PROTECTED] wrote:
> i would like to sort a list of lists. The list is first sorted on the
> second item in the sub-lists (which I can do), then on the third item
> (which I can't).
>
> eg. records = [['dog',1,2], ['chair',2,1], ['cat',1,3], ['horse',3,4],
> ['table',3,2], ['window',3,5]]
Thank you all for your very quick and informative replies. I was
basing this assumption that Å was classed as a standard 'A' from a
list of countries I was looking at (Wikipedia sorts it like this, too
- though this isn't what I was using
http://en.wikipedia.org/wiki/List_of_countries#A)
I will l
On 19 aug 2007, at 18.50, [EMAIL PROTECTED] wrote:
> Hey Guys,
>
> Maybe I'm missing something fundamental here, but if I have a list of
> Unicode strings, and I want to sort these alphabetically, then it
> places those that begin with unicode characters at the bottom. Is
> there a way to avoid t
On Aug 19, 8:09 pm, [EMAIL PROTECTED] (Alex Martelli) wrote:
[...]
> In both Swedish and Danish, I believe, A-with-ring sorts AFTER the
> letter Z in the alphabet; so, having Åaland (where I'm using Aa for
> A-with-ring, since this newsreader has some problem in letting me enter
> non-ascii charact
Alex Martelli wrote:
> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>...
Maybe I'm missing something fundamental here, but if I have a list of
Unicode strings, and I want to sort these alphabetically, then it
places those that begin with unicode characters at the bottom.
>...
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
...
> > > Maybe I'm missing something fundamental here, but if I have a list of
> > > Unicode strings, and I want to sort these alphabetically, then it
> > > places those that begin with unicode characters at the bottom.
...
> Anyway, I know _why_
On Aug 19, 6:01 pm, Stefan Behnel <[EMAIL PROTECTED]> wrote:
> [EMAIL PROTECTED] wrote:
> > Hey Guys,
>
> ... and girls - maybe ...
>
> > Maybe I'm missing something fundamental here, but if I have a list of
> > Unicode strings, and I want to sort these alphabetically, then it
> > places those that
[EMAIL PROTECTED] wrote:
> Hey Guys,
... and girls - maybe ...
> Maybe I'm missing something fundamental here, but if I have a list of
> Unicode strings, and I want to sort these alphabetically, then it
> places those that begin with unicode characters at the bottom.
That's because "Unicode" is
Bruno Desthuilliers wrote:
> John Salerno a écrit :
> (snip)
>
>> Oh I didn't sort then reverse, I just replaced sort with reverse.
>> Maybe that's why!
>
> Hmmm... Probably, yes...
>
> !-)
lol, this is what a couple months away from python does to me!
--
http://mail.python.org/mailman/listin
Steven Bethard <[EMAIL PROTECTED]> wrote:
> You don't need to use sorted() -- sort() also takes the key= and
> reverse= arguments::
>
> >>> lines = [('1995', 'aaa'), ('1997', 'bbb'), ('1995', 'bbb'),
> ... ('1997', 'aaa'), ('1995', 'ccc'), ('1996', 'ccc'),
> ...
On Thu, 01 Feb 2007 14:52:03 -0500, John Salerno wrote:
> Bruno Desthuilliers wrote:
>
>> You don't tell how these lines are formatted, but it's possible that you
>> don't even need a regexp here. But wrt/ sorting, the list of tuples with
>> the sort key as first element is one of the best solu
John Salerno <[EMAIL PROTECTED]> writes:
> Ah, so simply using sort() [on a list of tuples] will default to the
> first element of each tuple?
More precisely, list.sort will ask the elements of the list to compare
themselves. Those elements are tuples; two tuples will compare based
on comparison
John Salerno a écrit :
(snip)
> Oh I didn't sort then reverse, I just replaced sort with reverse. Maybe
> that's why!
Hmmm... Probably, yes...
!-)
--
http://mail.python.org/mailman/listinfo/python-list
Bruno Desthuilliers wrote:
>> One more thing. What if I want them in reverse chronological order? I
>> tried reverse() but that seemed to put them in reverse alphabetical
>> order based on the second element of the tuple (not the year).
>
> Really ?
>
> >>> lines = [('1995', 'aaa'), ('1997',
Steven Bethard a écrit :
> Bruno Desthuilliers wrote:
>
>> If you want to prevent this from happening and don't mind creating a
>> copy of the list, you can use the sorted() function with the key and
>> reverse arguments and operator.itemgetter:
>>
(snip)
>
> You don't need to use sorted() -- s
Bruno Desthuilliers wrote:
> If you want to prevent this from happening and don't mind creating a
> copy of the list, you can use the sorted() function with the key and
> reverse arguments and operator.itemgetter:
>
> >>> lines = [('1995', 'aaa'), ('1997', 'bbb'), ('1995', 'bbb'),
> ('1997', '
John Salerno a écrit :
> John Salerno wrote:
>
>> Bruno Desthuilliers wrote:
>>
>>> John Salerno a écrit :
>>>
Hi everyone. If I have a list of tuples, and each tuple is in the form:
(year, text) as in ('1995', 'This is a citation.')
How can I sort the list so that they ar
John Salerno a écrit :
> Bruno Desthuilliers wrote:
>
>> John Salerno a écrit :
>>
>>> Hi everyone. If I have a list of tuples, and each tuple is in the form:
>>>
>>> (year, text) as in ('1995', 'This is a citation.')
>>>
>>> How can I sort the list so that they are in chronological order based
>
John Salerno a écrit :
> Bruno Desthuilliers wrote:
>
>> You don't tell how these lines are formatted, but it's possible that
>> you don't even need a regexp here. But wrt/ sorting, the list of
>> tuples with the sort key as first element is one of the best solutions.
>
>
> Ah, so simply using
> -Original Message-
> From: John Salerno [mailto:[EMAIL PROTECTED]
> Sent: Thursday, February 01, 2007 11:54 AM
> To: python-list@python.org
> Subject: Re: Sorting a list
>
> Bruno Desthuilliers wrote:
> > John Salerno a écrit :
> >> Hi everyone.
John Salerno wrote:
> Bruno Desthuilliers wrote:
>> John Salerno a écrit :
>>> Hi everyone. If I have a list of tuples, and each tuple is in the form:
>>>
>>> (year, text) as in ('1995', 'This is a citation.')
>>>
>>> How can I sort the list so that they are in chronological order based
>>> on the
John Salerno wrote:
> Bruno Desthuilliers wrote:
>> John Salerno a écrit :
>>> Hi everyone. If I have a list of tuples, and each tuple is in the form:
>>>
>>> (year, text) as in ('1995', 'This is a citation.')
>>>
>>> How can I sort the list so that they are in chronological order based
>>> on the
Bruno Desthuilliers wrote:
> John Salerno a écrit :
>> Hi everyone. If I have a list of tuples, and each tuple is in the form:
>>
>> (year, text) as in ('1995', 'This is a citation.')
>>
>> How can I sort the list so that they are in chronological order based
>> on the year?
>
> Calling sort() on
Bruno Desthuilliers wrote:
> You don't tell how these lines are formatted, but it's possible that you
> don't even need a regexp here. But wrt/ sorting, the list of tuples with
> the sort key as first element is one of the best solutions.
Ah, so simply using sort() will default to the first ele
1 - 100 of 152 matches
Mail list logo