Re: Most efficient way to "pre-grow" a list?

2009-11-07 Thread Luis Alberto Zarrabeitia Gomez
Quoting Andre Engels : > On Sat, Nov 7, 2009 at 8:25 PM, Luis Alberto Zarrabeitia Gomez > wrote: > > > > Ok, he has a dict. > > > > Now what? He needs a non-sparse array. > > Let d be your dict. > > Call the zeroeth place in your array d[0], the first

Re: Most efficient way to "pre-grow" a list?

2009-11-07 Thread Luis Alberto Zarrabeitia Gomez
Quoting Bruno Desthuilliers : > > Another situation where one may want to do this is if one needs to > > initialize a non-sparse array in a non-sequential order, > > Then use a dict. Ok, he has a dict. Now what? He needs a non-sparse array. -- Luis Zarrabeitia Facultad de Matemática y Comput

Re: id( ) function question

2009-10-14 Thread Luis Alberto Zarrabeitia Gomez
> It's believable if id({}) does the following: > > 1. Construct an empty dict > 2. Take the id of the dict > 3. Reduce the reference-count on the now-unneeded dict. > > It's not too hard for the second empty dict to get allocated in the same > memory that the first one (now dereferenced and de

Re: Subclass dynamically

2009-08-08 Thread Luis Alberto Zarrabeitia Gomez
Quoting Robert Dailey : > Hey, > > I have a class that I want to have a different base class depending on > a parameter that I pass to its __init__method. For example > (pseudocode): 1- Are you sure that you want that behavior? Given that in python, a class is just a particular case of invocabl

Re: initializing with empty list as default causes freaky problems

2009-07-28 Thread Luis Alberto Zarrabeitia Gomez
Quoting Reckoner : > Hi, > > Observe the following: > > In [202]: class Foo(): >.: def __init__(self,h=[]): >.: self.h=h [...] > In [207]: f.h.append(10) > > In [208]: f.h > Out[208]: [10] > > In [209]: g.h > Out[209]: [10] > > The question is: why is g.h updated

Re: Help understanding the decisions *behind* python?

2009-07-22 Thread Luis Alberto Zarrabeitia Gomez
Quoting Inky 788 : > > The good reason is the immutability, which lets you use > > a tuple as a dict key.   > > Thanks for the reply Hendrik (and Steven (other reply)). Perhaps I'm > just not sophisticated enough, but I've never wanted to use a list/ > tuple as a dict key. This sounds like obscu

Re: missing 'xor' Boolean operator

2009-07-16 Thread Luis Alberto Zarrabeitia Gomez
Quoting Jean-Michel Pichavant : > Emile van Sebille wrote: > > On 7/16/2009 7:04 AM Unknown said... > >> On 2009-07-16, Emile van Sebille wrote: > >>> daysInAdvance = int(inputVar) or 25 > >> > >> I don't get it. That doesn't work right when inputVar == "0". > >> > > Aah, but you didn't get to

Re: Exotic Logics

2009-06-17 Thread Luis Alberto Zarrabeitia Gomez
Quoting Lie Ryan : > pdpi wrote: > > On Jun 17, 5:37 pm, Lie Ryan wrote: > >> Steven D'Aprano wrote: > >>> On Tue, 16 Jun 2009 22:46:14 -0700, William Clifford wrote: > I was staring at a logic table the other day, and I asked myself, "what > if one wanted to play with exotic logics; h

Re: Adding a Par construct to Python?

2009-05-21 Thread Luis Alberto Zarrabeitia Gomez
Quoting Carl Banks : > I don't have any reply to this post except for the following excerpts: > > On May 20, 8:10 pm, Luis Alberto Zarrabeitia Gomez > wrote: > > 2- in [almost] every other language, _you_ have to be aware of the > critical > > sections when mul

Re: Adding a Par construct to Python?

2009-05-20 Thread Luis Alberto Zarrabeitia Gomez
Quoting Carl Banks : > On May 20, 4:07 pm, Luis Zarrabeitia wrote: > > On Wednesday 20 May 2009 06:16:39 pm Aahz wrote: > > The designers of Python made a design decision(**) that extension > writers would not have to take care of locking. They could have made > a different decision, they just

Re: pushback iterator

2009-05-17 Thread Luis Alberto Zarrabeitia Gomez
Quoting Mike Kazantsev : > And if you're "pushing back" the data for later use you might just as > well push it to dict with the right indexing, so the next "pop" won't > have to roam thru all the values again but instantly get the right one > from the cache, or just get on with that iterable unt

Re: Self function

2009-05-06 Thread Luis Alberto Zarrabeitia Gomez
Quoting Steven D'Aprano : > But regardless, everyone is missing the most important point: why are you > copying and pasting code in the first place? That is surely very close to > the top of the list of Worst Ever Anti-Patterns, and it should be avoided > whenever possible. [btw, I took this

Re: Self function

2009-05-06 Thread Luis Alberto Zarrabeitia Gomez
Quoting Rhodri James : > >> I'm sorry, but while I'm mildly positive towards the proposal (and more > >> so towards Aaron's decorator), I don't buy this argument at all. What > >> is broken about your editor's global search-and-replace function that > >> makes it "usually useless" for making the

Re: Multiprocessing.Queue - I want to end.

2009-05-05 Thread Luis Alberto Zarrabeitia Gomez
Quoting Cameron Simpson : > | And as it happens I have an IterableQueue class right here which does > | _exact_ what was just described. You're welcome to it if you like. > | Added bonus is that, as the name suggests, you can use the class as > | an iterator: > | for item in iterq: > | ...

Re: Multiprocessing.Queue - I want to end.

2009-05-03 Thread Luis Alberto Zarrabeitia Gomez
Quoting Dennis Lee Bieber : > I'm not familiar with the multiprocessing module and its queues but, > presuming it behaves similar to the threading module AND that you have > design control over the consumers (as you did in the sample) make a > minor change. > > queue.put(None) ONCE i

Re: Multiprocessing.Queue - I want to end.

2009-05-03 Thread Luis Alberto Zarrabeitia Gomez
Quoting Hendrik van Rooyen : > "Luis Zarrabeitia" wrote: > > 8< ---explanation and example of one producer, > 8< ---more consumers and one queue > > >As you can see, I'm sending one 'None' per consumer, and hoping that no > >consumer will read more than

Re: sorting two corresponding lists?

2009-04-20 Thread Luis Alberto Zarrabeitia Gomez
Quoting Esmail : > items = [apple, car, town, phone] > values = [5, 2, 7, 1] > > I would like to sort the 'items' list based on the 'values' list so > that I end up with the following two list: > > items = [town, apple, car, phone] > values = [7, 5, 2, 1] I've used this sometimes: === [unte

Re: any(), all() and empty iterable

2009-04-14 Thread Luis Alberto Zarrabeitia Gomez
Quoting John O'Hagan : > An exception, or at least a specific mention of the case of empty iterables > in the docs (as Tim Chase suggested), would have baffled me less than my > program telling me that the same items were both ubiquitous and entirely > absent from a list of sets! Well, they _w

Re: Imports in python are static, any solution?

2009-04-13 Thread Luis Alberto Zarrabeitia Gomez
Quoting Ravi : > > This is problematic. Well I want i to change with foo.fi() . You can't. i and foo.i are _different_ variables that just happen to share the same value initially. What you are observing is no different than i = 10 j = i i = 99 print i # prints 99 print j # print 10 May I

Re: any(), all() and empty iterable

2009-04-11 Thread Luis Alberto Zarrabeitia Gomez
Quoting John O'Hagan : > Hi, > > I was getting some surprising false positives as a result of not expecting > this: > > all(element in item for item in iterable) > > to return True when 'iterable' is empty. > [...] > any(element in item for item in iterable) > > which returns False when 'i

Re: nested looping

2009-04-08 Thread Luis Alberto Zarrabeitia Gomez
Quoting PK : > So I'm trying to see whats the cleanest way to do this: > > I have a > > checklist = [ax, bx, by, cy ..] (a combination of a,b,c with x and y, > either both on one) > > allist = [a,b,c,] > xlist = [x, y, ..] > [...] > now the problem is I want to include alpha in missing l

Re: python needs leaning stuff from other language

2009-04-02 Thread Luis Alberto Zarrabeitia Gomez
Quoting Esmail : > Diez B. Roggisch wrote: > > > > some_list[:] = [] > > I agree that this is nice and clear, Not very intuitive, though, until you learn the syntax. (but, slice accessing and slice assignment are among the first few things one learns about python anyway, and once you learn it,

Re: python needs leaning stuff from other language

2009-04-02 Thread Luis Alberto Zarrabeitia Gomez
Quoting online.serv...@ymail.com: > python's list needs a thing list.clear() like c# arraylist It has: >>> l[:] = [] > python needs a writeline() method Now, that could be useful, a writeline method that knew the EOL convention for the OS and were not as deceiving as the current .writeline

distutils, No module named numpy.distutils.fcompiler.conv_template

2009-03-30 Thread Luis Alberto Zarrabeitia Gomez
I'm trying to compile the wrappers for ANN (Approximate Nearest Neighbor) from http://scipy.org/scipy/scikits/wiki/AnnWrapper, either the main one (scikits) or the attachment in the main page. However, the command "python setup.py build" produces the exception: "ImportError: No module named nu