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.
精彩评论