In article <[EMAIL PROTECTED]>,
Martin v. Löwis <[EMAIL PROTECTED]> wrote:

>> The sorting is in a performance-critical part of the system, so the
>> overhead of evaluating a key function is not insignificant.
>
>Can you easily produce an example? It doesn't have to be real data,
>but should have the structure (typewise) of the real data. I would
>like to perform some measurements. For example, I could imagine that
>
>l = []
>for i in range(1000):
>  x = random.randint(0,100)
>  if x < 4: l.append(None)
>  else: l.append(x)
>
>might adequately model your problem.

Sorry for the delay in replying. Yes, that's not far off. Most of the
time the lists contain strings, though. A better approximation might
be to read lines from a file and randomly replace them with Nones:

l = []
for line in open("bigfile.txt"):
    x = random.randint(0,100)
    if x < 4: l.append(None)
    else: l.append(line)

And maybe once in a while you end up with something not dissimilar to:

l = []
for line in open("bigfile.txt"):
    x = random.randint(0,100)
    if x < 4: l.append(None)
    elif x < 5: l.append([line,line])
    else: l.append(line)

In that kind of case it doesn't really matter what happens to list
items in the sort order, but it's important it doesn't fail to sort
the ones that are strings.

Cheers,

Duncan.

-- 
 -- Duncan Grisby         --
  -- [EMAIL PROTECTED]     --
   -- http://www.grisby.org --
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to