What is the easiest way to convert Python dict e.g.:
a = {'a': 'value', 'b': 'another_value', ...}
into string using user format e.g.:
'%s - %s\n'
so it gives me:
a - value
b - another_value
This works, but maybe there is something shorter/better using map (without iterating over collection)
''.join(['%s %s\n' % o for o in a.items()])
You can omit the square brackets to avoid building the intermediate list:
Since you’re asking about
map, here is one way to write it usingmap:It’s a matter of preference, but I personally find it harder to read than the original version.