Re: in place list modification necessary? What's a better idiom?

2009-04-08 Thread MooMaster
On Apr 6, 10:43 pm, Carl Banks pavlovevide...@gmail.com wrote: MooMaster wrote: So I'm reading in values from a file, and for each column I need to dynamically discover the range of possible values it can take and quantize if necessary. This is the solution I've come up with: code def

Re: in place list modification necessary? What's a better idiom?

2009-04-08 Thread MooMaster
On Apr 7, 12:40 am, Peter Otten __pete...@web.de wrote: Peter Otten wrote: MooMaster wrote: Now we can't calculate a meaningful Euclidean distance for something like Iris-setosa and Iris-versicolor unless we use string-edit distance or something overly complicated, so instead we'll use a

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread Peter Otten
MooMaster wrote: Now we can't calculate a meaningful Euclidean distance for something like Iris-setosa and Iris-versicolor unless we use string-edit distance or something overly complicated, so instead we'll use a simple quantization scheme of enumerating the set of values within the column

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread Peter Otten
Peter Otten wrote: MooMaster wrote: Now we can't calculate a meaningful Euclidean distance for something like Iris-setosa and Iris-versicolor unless we use string-edit distance or something overly complicated, so instead we'll use a simple quantization scheme of enumerating the set of

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread Carl Banks
On Apr 7, 12:38 am, Peter Otten __pete...@web.de wrote: MooMaster wrote: Now we can't calculate a meaningful Euclidean distance for something like Iris-setosa and Iris-versicolor unless we use string-edit distance or something overly complicated, so instead we'll use a simple quantization

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread Peter Otten
Carl Banks wrote: On Apr 7, 12:38 am, Peter Otten __pete...@web.de wrote: MooMaster wrote: Now we can't calculate a meaningful Euclidean distance for something like Iris-setosa and Iris-versicolor unless we use string-edit distance or something overly complicated, so instead we'll use a

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread andrew cooke
Carl Banks wrote: import collections import itertools def createInitialCluster(fileName): fixedPoints = [] # quantization is a dict that assigns sequentially-increasing numbers # to values when reading keys that don't yet exit quantization =

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread R. David Murray
andrew cooke and...@acooke.org wrote: Carl Banks wrote: import collections import itertools def createInitialCluster(fileName): fixedPoints = [] # quantization is a dict that assigns sequentially-increasing numbers # to values when reading keys that don't yet exit

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread MRAB
Carl Banks wrote: MooMaster wrote: So I'm reading in values from a file, and for each column I need to dynamically discover the range of possible values it can take and quantize if necessary. This is the solution I've come up with: [snip] #harvested from

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread andrew cooke
just playing around - doesn't work with 3.0 due to lack of pattern binding (which i think is coming back in 3.1?) from collections import defaultdict from itertools import count def mkdict(): return defaultdict(count().next) ... converters = defaultdict(mkdict) def to_float((i, s)): ...

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread andrew cooke
R. David Murray wrote: [...] try: dimensions.append(float(s)) except: dimensions.append(float(quantization[s])) No, no, no; never use a bare except! :) can you explain why? i can't think of any reason why the code would be better catching a specific exception. as a general

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread MRAB
andrew cooke wrote: R. David Murray wrote: [...] try: dimensions.append(float(s)) except: dimensions.append(float(quantization[s])) No, no, no; never use a bare except! :) can you explain why? i can't think of any reason why the code would be better catching a specific

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread R. David Murray
On Tue, 7 Apr 2009 at 09:01, andrew cooke wrote: R. David Murray wrote: [...] try: dimensions.append(float(s)) except: dimensions.append(float(quantization[s])) No, no, no; never use a bare except! :) can you explain why? i can't think of any reason why the code would be

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread andrew cooke
MRAB wrote: andrew cooke wrote: R. David Murray wrote: [...] try: dimensions.append(float(s)) except: dimensions.append(float(quantization[s])) No, no, no; never use a bare except! :) can you explain why? i can't think of any reason why the code would be better catching a

in place list modification necessary? What's a better idiom?

2009-04-06 Thread MooMaster
A similar discussion has already occurred, over 4 years ago: http://groups.google.com/group/comp.lang.python/browse_thread/thread/b806ada0732643d/5dff55826a199928?lnk=gstq=list+in+place#5dff55826a199928 Nevertheless, I have a use-case where such a discussion comes up. For my data mining class I'm

Re: in place list modification necessary? What's a better idiom?

2009-04-06 Thread Carl Banks
MooMaster wrote: So I'm reading in values from a file, and for each column I need to dynamically discover the range of possible values it can take and quantize if necessary. This is the solution I've come up with: code def createInitialCluster(fileName): #get the data from the file