long lists

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Mon May 7 08:55:27 EDT 2007


In <1178540073.988964.196860 at w5g2000hsg.googlegroups.com>, Merrigan wrote:

> The Script it available at this url : http://www.lewendewoord.co.za/theScript.py
> 
> P.S. I know it looks like crap, but I'm a n00b, and not yet through
> the OOP part of the tutorial.

One spot of really horrible runtime is the `comp_are()` function, it has
quadratic runtime. Why the funny spelling BTW?

Why are you binding the objects to new names all the time and calling
`str()` repeatedly on string objects?  The names `a`, `b` and `fn2up` are
unnecessary, you can use `file1`, `file2` and `filename` instead.  And
``str(str(b))`` on a string object is a no-operation.  It's the same as
simply writing ``b``.

Those two nested ``for``-loops can be replaced by converting both lists
into `set()` objects, calculating the difference and convert back to a
sorted list:

def compare(remote, local):
    return sorted(set(local) - set(remote))

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list