Say I have an arbitrary list:
qw = ['a', [['tag', '1'], ['tag', '2']]]
I need to build html with <blockquote> (just a python string; each element of list should be wrapped in blockquote tag accordingly to hierarchy):
<blockquote> a
<blockquote> tag
<blockquote> 1 </blockquote>
</blockquote>
<blockquote> tag
<blockquote> 2 </blockquote>
</blockquote>
</blockquote>
The result:
For example I have a string test='str1str2str34' and some rules to split it into list:
['str1str2str34', [
['str1', ['str', '1']],
['str2', ['str', '2']],
['str34', ['str', '3', '4']]
]
]
The rendered result based blockquote tags:
So, I trying to change the recursive generator (for flattening a list):
def flatten(l):
for el in l:
if isinstance(el, collections.Iterable) and not isinstance(el, basestring):
for sub in flatten(el):
yield sub
else:
yield el
But really nothing comes of it.


list(flatten(qw)).