473,385 Members | 1,392 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Re: Schwartzian transform for tuple in list

On Wed, Sep 24, 2008 at 2:02 PM, David Di Biase <da**********@gmail.comwrote:
Hi,

I have a rather large list structure with tuples contained in them (it's
part of a specification I received) looks like so:
[(x1,y1,r1,d1),(x2,y2,r2,d2)...]

The list can range from about 800-1500 tuples in size and I'm currently
sorting it with this:

a_list.sort(lambda a, b: cmp(b[3], a[3]))
You'd probably be better off using the 'key' keyword argument to
..sort(), which is made for the Schwartzian Transform:

a_list.sort(key=lambda x: x[3])

This sorts the list items by the value produced by the key function
for each item. It's also (IIRC) faster than using a comparison
function like you're currently doing.

Regards,
Chris
>
I'm actually sorting it by the last value in the tuple (d2). I have been
researching more efficient sorting algorithms and came across Schwartzian
transform via these links:

http://www.biais.org/blog/index.php/...ing-efficiency
http://dev.fyicenter.com/Interview-Q...n_Python_.html

I get what's happening (sorta...errr...lol) but I'm not sure if it is more
efficient in my scenario, if it is then I have no idea how to implement it
properly :-/

Would be great if a true expert would offer a suggestion for me...

Thanks!

David

--
http://mail.python.org/mailman/listinfo/python-list
--
Follow the path of the Iguana...
http://rebertia.com
Sep 24 '08 #1
0 1477

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Carlo v. Dango | last post by:
Hello there. I have a function which as an argument takes a tuple and either returns that tuple or a mutated version of it. The problem is that tuples are imutable, hence I have to create a new...
9
by: Yomanium Yoth Taripoät II | last post by:
HI, 1) what are the differences between list and tuple? 2) how to concatenate tuple and list? no method, no opérator? 3) im looking the fucking manual, and cant add value in my tuple, when it...
2
by: Ishwar Rattan | last post by:
I am a little confused about a list and a tuple. Both can have dissimilar data-type elements, can be returned by functions. The only difference that I see is that list is mutable and tuple is...
5
by: Xah Lee | last post by:
suppose i'm going to have a data structure like this: , , , , .... ] should i use (width,height) or ?
4
by: Dean Card | last post by:
Okay, so here is the situation. I have need to do some on-the-fly image creation. I have everything working great except for the last part of it, applying a perspective type transform to the...
5
by: er | last post by:
hi, is anyone aware of a library that generalizes transform, for_each? e.g. transform( vec1.begin(), vec1.end(), vec2.begin(), vec3.begin(),
3
KevinADC
by: KevinADC | last post by:
If you are entirely unfamiliar with using Perl to sort data, read the "Sorting Data with Perl - Part One and Two" articles before reading this article. Beginning Perl coders may find this article...
0
by: Matt Nordhoff | last post by:
Chris Rebert wrote: Yes, using 'key' is faster than 'cmp'. If you have Python 2.4 or newer, it would also be slightly faster to use operator.itemgetter() instead of a lambda: --
0
by: Hatem Nassrat | last post by:
on Wed Jun 13 10:17:24 CEST 2007, Diez B. Roggisch deets at nospam.web.de wrote: Well I have looked into this and it seems that using the list comprehension is faster, which is...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.