[Zope] sort in python script dynamically?
Terry Hancock
hancock at anansispaceworks.com
Thu Jan 8 17:11:08 EST 2004
On Thursday 08 January 2004 09:56 am, Jaroslav Lukesh wrote:
> I want to sort by value of i[0] before "i" is taken to FOR. So it is
> possible to do something like
>
>
> for i in self.objectItems('Folder').sort(i[0])
The reason this doesn't work as written is because the .sort()
method works in-place and does not return a value. Also,
sort needs a function that does the comparison. You
want:
values = self.objectItems('Folder')
values.sort(lambda a,b: cmp(a[0],b[0])
for i in values:
# do stuff
pass
Cheers,
Terry
--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com
More information about the Zope
mailing list