Firstly, the answer is incorrect :
','.join('%s,%s' % i for i in D.iteritems())
This answer is incorrect because, although associative arrays in PHP have this order, dictionaries in Python do not. The way to compensate for this is to either use an ordered display type (e.g. OrderedDict ), or force an explicit order to be set:
','.join('%s,%s' % (k, D[k]) for k in ('a', 'c'))
Ignacio Vazquez-Abrams
source share