Data structure recommendation?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Tue Apr 8 18:21:19 EDT 2008


More bits from your code:

neighbours = list()
==>
neighbours = []

If you have a recent enough version of Python you can use:
candidate_is_neighbour = any(distance < n[1] for n in neighbours)
Instead of:
candidate_is_neighbour = bool([1 for n in neighbours if distance <
n[1]])

It's shorter & simpler, and it stops as soon as it finds a true
condition.

Bye,
bearophile



More information about the Python-list mailing list