On 17/07/2014 17:23, Jose Amoreira wrote:
Hello,
On 07/17/2014 12:05 AM, Alan Gauld wrote:
Just throwing this idea in without really thinking about it...
Would itertools.groupby work?
It takes a sorted collection and groups the items found based on a key
function. If the key function deemed two items identical if they were
within distance X of each other then groupby might help.
The itertools functions are generally space efficient and
therefore good for large volumes of data.
Thanks for the suggestion, I didn't know about groupby. I gave it a try.
The key function argument is optional; if we don't supply one, grouby
groups *equal* list elements. But I want to group *close enough*
elements (close enough meaning that their distance is less than some
reference value), and I didn't manage to specify a key function in a
form suitable for use with groubpy. I should spend some more time
studying the examples.
Anyway, thanks a lot, it's always good to know a new module in the
standard library.
Ze
Also take a look at the operator module
https://docs.python.org/3/library/operator.html#module-operator as it's
often used with itertools.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
---
This email is free from viruses and malware because avast! Antivirus protection
is active.
http://www.avast.com
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor