基本上,我有一个表格字典:
'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中的等价物是什么?提前致谢
答案 0 :(得分:3)
一个基本的例子:
['%f, %s' % (x,y) for _,_,_,x,_,y in d.values()]
您可以调整格式字符串以更好地控制输出。 底层语法构造称为list comprehension
答案 1 :(得分:1)
[', '.join((value[3], value[5])) for value in my_dict.iteritems()]