Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #31866
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2012-10-21 16:29 -0700 |
| Message-ID | <d1dbc8a7-1ec6-474c-96d7-b95a066125dd@googlegroups.com> (permalink) |
| Subject | Recursive Generator Error? |
| From | David <zhushenli@gmail.com> |
I have a tree-like data structure, the basic elements are hash tables,
and they are grouped into lists, like [[{'a':1},[{'b':2}]]].
And I want to flat the lists and visit hash table one by one, like {'a':1}, {'b':2}.
But my program didn't work as I wish. When it entered the 2nd
flat_yield, it threw a GeneratorExit. Is there anything wrong?
Thank you very much!
#- - - - - - - - - -
def flat_yield(tbl_list):
for t in tbl_list:
if type(t) == type({}):
yield t
elif type(t) == type([]):
flat_yield(t)
a = [[{'a':1},[{'b':2}]]]
for i in flat_yield(a):
print i
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Recursive Generator Error? David <zhushenli@gmail.com> - 2012-10-21 16:29 -0700
Re: Recursive Generator Error? Terry Reedy <tjreedy@udel.edu> - 2012-10-21 19:59 -0400
Re: Recursive Generator Error? David <zhushenli@gmail.com> - 2012-10-21 17:40 -0700
Re: Recursive Generator Error? David <zhushenli@gmail.com> - 2012-10-21 17:40 -0700
Re: Recursive Generator Error? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-10-22 02:36 +0000
csiph-web