开发者

Is there a shorter code to join the keys and values for a dictionary?

Is there a shorter or better snippet that accomplishes the following:

>>> h = { 'apple' : 'ipad' , 'amazon': 'kindle' }
>>开发者_开发问答> [' '.join(item) for item in zip( h.keys(), h.values())]
[ 'apple ipad', 'amazon kindle' ]


>>> [' '.join(item) for item in h.iteritems()]
['amazon kindle', 'apple ipad']

>>> map(' '.join, h.iteritems())
['amazon kindle', 'apple ipad']

But avoid using map() these days. And list comprehensions if you can help it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜