Re: I can't get multi-dimensional array to work...
- From: Carsten Haese <carsten@xxxxxxxxxxx>
- Date: Fri, 30 Mar 2007 21:55:42 -0400
On Fri, 2007-03-30 at 14:34 -0700, erikcw wrote:
On Mar 30, 5:23 pm, FlipFish2...@xxxxxxxxx wrote:
I haven't tested it, but superficially I'd suggest giving this a try:
def endElement(self, name):
if name == 'row' :
if not self.data.has_key(self.parent):
self.data[self.parent] = {}
if not self.data[self.parent].has_key(self.child):
self.data[self.parent][self.child] = []
self.data[self.parent]
[self.child].append((self.creativeid, self.clicks, self.imps))
That seems to have done the trick! I can't believe I spent all
afternoon trying to figure that out!! Thanks a million!
Since you're already using dictionaries, as an alternative solution you
could construct a single dictionary that is keyed on two-dimensional
tuples (also known as ordered pairs). Combine that with the setdefault
method to initialize new entries and you end up with something like
this:
def endElement(self, name):
if name == 'row':
entry = self.data.setdefault((self.parent,self.child),[])
entry.append(...)
-Carsten
.
- References:
- I can't get multi-dimensional array to work...
- From: erikcw
- Re: I can't get multi-dimensional array to work...
- From: FlipFish2007
- Re: I can't get multi-dimensional array to work...
- From: erikcw
- I can't get multi-dimensional array to work...
- Prev by Date: Re: Indentation for code readability
- Next by Date: Re: Cheeseshop needs mirrors
- Previous by thread: Re: I can't get multi-dimensional array to work...
- Next by thread: Mouse click in python
- Index(es):
Relevant Pages
|