Hi all,
I have solved my problem, but would like to know if what I accomplished
can be done with different data using list comprehensions.
the list I want to sort has the following format:
elements = [
(codigo, [ cant, importe, porc]),
(codigo, [ cant, importe, porc]),
...
]
Actual data is:
In
On 12/04/06, Victor Bouffier [EMAIL PROTECTED] wrote:
elements = [
(codigo, [ cant, importe, porc]),
(codigo, [ cant, importe, porc]),
...
]
And I want to sort descending on 'importe', which is x[1][1] for x in
elements.
In python 2.4, you could achieve this by saying:
Hi Victor,
I've gotta say that I much prefer the second version here.
temporal = []
temporal = [ [x[1][1], (x[0], description[x[0]],
x[1][0], x[1][1], x[1][2] ) ] for x in elements ]
temporal.sort()
temporal.reverse() # sort descending
elements = [ x[1] for x in temporal ]
On Tue, 2006-04-11 at 23:42 +0100, Alan Gauld wrote:
Hi Victor,
I've gotta say that I much prefer the second version here.
temporal = []
temporal = [ [x[1][1], (x[0], description[x[0]],
x[1][0], x[1][1], x[1][2] ) ] for x in elements ]
temporal.sort()
temporal.reverse()
Victor Bouffier wrote:
If the second element in each array passed as x is of variable length
(that is, it has a different element count than three, in this case),
the program needs to extend the list instead. Without list
comprehensions, and the added capability to utilize and sized list as a
On Tue, 2006-04-11 at 22:17 -0400, Kent Johnson wrote:
Victor Bouffier wrote:
If the second element in each array passed as x is of variable length
(that is, it has a different element count than three, in this case),
the program needs to extend the list instead. Without list