[Tutor] Question about style
Alan Gauld
alan.gauld at btinternet.com
Thu Jul 17 01:05:24 CEST 2014
On 16/07/14 12:49, Jose Amoreira wrote:
> Hello
> I wrote a function that, given a list of numbers, finds clusters of
> values by proximity and returns a reduced list containing the centers of
> these clusters. However, I find it rather unclear. I would appreciate
> any comments on how pythonic my function is and suggestions to improve
> its readability.
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.
Just a thought.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list