【发布时间】:2015-08-03 10:10:39
【问题描述】:
这是我的代码:
html_tags = [{'tag': 'a',
'attribs': [('class', 'anchor'),
('aria-hidden', 'true')]}]
我可以通过一级for循环和一级映射来做到这一点,如下所示:
for index, tag in enumerate(html_tags):
html_tags[index]['attribs'] = map(lambda x: '@{}="{}"'.format(*x), tag['attribs'])
print html_tags
但是,这是我的输出(结果):
[{'attribs': ['@class="anchor"', '@aria-hidden="true"'], 'tag': 'a'}]
如何做两级嵌套map并输出相同的结果。
【问题讨论】:
-
你的预期输出是什么?
标签: python list python-2.7 dictionary