python - Dictionary Comprehension to generate values of built-in type -
i dictionary comprehension list of keys built-in type of str
values.
headers = ['header1', 'header2', 'header3'] print dict([(x,str) x in headers])
output:
{'header2': <type 'str'>, 'header3': <type 'str'>, 'header1': <type 'str'>}
desired output:
{'header2': str, 'header3': str, 'header1': str}
you do have dictionary built-in str
in it.
the <type 'str'>
due print
call use value obtained calling objects' __str__
when prints it. value str
<type 'str'>
.
if save dictionary, access 1 of members , use you'll see is str
class:
>>> d = dict([(x,str) x in headers]) >>> d['header1'](123) '123'
Comments
Post a Comment