determining type
Alex
alex at somewhere.round.here
Wed Mar 22 12:10:24 EST 2000
> I'm trying to write a function to format the dictionary so that when I
> print it, rather than looking like {'foo' : 'bar', 'who' : 'what'}, it
> looks like
>
> {
> 'foo' : 'bar',
> 'who' : 'what',
> }
import string
def dictionary_str (d):
output = ['{\n']
for pair in d.items ():
output.append ('%s : %s,\n' % tuple (map (repr, pair)))
output.append ('}')
return string.join (output, '')
print dictionary_str ({'foo' : 'bar', 'who' : 'what'})
Hope this helps.
Alex.
More information about the Python-list
mailing list