遍历列表的Python列表并创建一个新列表
基本上,我有一个以下形式的字典:
'the trip':('The Trip','www.SearchHero.com',"See sponsored listings for 'The Trip.' Click here!",0.1,'The Trip','3809466'),
'post office':('Post Office','www.SearchHero.com',"See sponsored listings for 'Post Office.' Click here!",0.1,'Post Office','5803938'),
'balanced diets':('Last Minute Deals','www.SearchHero.com',"See sponsored listings for 'Last Minute Deals.' Click here!",0.1,'Last Minute Deals','1118375')
我想输出以下形式的列表:
{'.1, 3809466', '.1, 5803938', '.1, '1118375'}
我是 Python 新手,但在 Ruby 中我知道我会使用 map 函数。 python 中的等价物是什么?提前致谢
Basically, I have a dictionary of the form:
'the trip':('The Trip','www.SearchHero.com',"See sponsored listings for 'The Trip.' Click here!",0.1,'The Trip','3809466'),
'post office':('Post Office','www.SearchHero.com',"See sponsored listings for 'Post Office.' Click here!",0.1,'Post Office','5803938'),
'balanced diets':('Last Minute Deals','www.SearchHero.com',"See sponsored listings for 'Last Minute Deals.' Click here!",0.1,'Last Minute Deals','1118375')
I want to output a list of the form:
{'.1, 3809466', '.1, 5803938', '.1, '1118375'}
I am new to Python, but in Ruby I know I'd use the map function. What is the equivalent in python? Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个基本示例:
您可以调整格式字符串以更好地控制输出。
底层语法构造称为列表理解
A basic example:
you can adapt the format string to have more control over the output.
The underlying syntax construct is called a list comprehension