[Tutor] My first recursive function...
Liam Clarke
cyresse at gmail.com
Thu Jul 28 13:39:02 CEST 2005
> [key, info] you mean...
Oops. That'd be the one.
Looks good to me other than the name :-) I would call it toDict() or
> toNestedDict() maybe; IMO a function named isXXX should just return True or
> False.
Yah, it started off as a boolean return, and then I decided to go for the
big one, so to speak,
having heard recursion spoken in hushed awe and/or spat out like a swear
word.
> Are there any other pitfalls with recursion I need to watch for?
> > (I'm also expecting the occasional list that is simply a list of
> > strings, hence the and clause in the isinstance check.)
>
> The biggest pitfall I can think of is that you get into an infinite
> recursion. This can happen when the recursive call for some reason uses the
> same arguments as were passed to the caller, or when the exit condition is
> never met. I think you're fine on both counts here.
Ah, cool. Now I can run this over my full data set and see what interesting
exceptions and errors I get.
Does this mean you gave up on pyparsing Dict?
To some extent. I could use it, but to be honest, the my limited
understanding means the effort:effect ratio doesn't make it worth my while.
The author of pyparsing helped me out amazingly, my parse time for a full
set of data dropped from nearly 6 hours (!) to 3 minutes once he
straightened out my grammar, and I think I've taken enough of his time as it
is.
My problem is a lot of repeated items like merchant = { tag = LAT,...}so to
utilise a pp Dict, I'd have to implement functions into the grammar to pop
the the tag name to use as a dictionary key, and I'd rather not mess with
the grammar any further, in case I break it, or slow it down. :S
My understanding of pyparsing is basic, to say the least, so I'm following
the path of least resistance here, as I get a list returned which is (now)
simple enough to turn into a dictionary.
There's some non-consistent 'special cases' in the data structure, which I
can handle a lot simpler when I've written the function which is creating my
dictionary.
Regards,
Liam Clarke
_______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
--
'There is only one basic human right, and that is to do as you damn well
please.
And with it comes the only basic human duty, to take the consequences.'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050728/cdea0643/attachment.htm
More information about the Tutor
mailing list