Output Python Dictionary 'Values' as binary format -
i have trying solve issue while. have looked simple answer no avail. appreciated. have created python dictionary , trying format output of values binary data. in other words each string value in dictionary want output binary value. code , error getting below.
pigpen = {} pigpen['a'] = 'etl' pigpen['b'] = 'etm' pigpen['c'] = 'etr' pigpen['d'] = 'eml' pigpen['e'] = 'emm' pigpen['f'] = 'emr' pigpen['g'] = 'ebl' pigpen['h'] = 'ebm' pigpen['i'] = 'ebr' pigpen['j'] = 'dtl' pigpen['k'] = 'dtm' pigpen['l'] = 'dtr' pigpen['m'] = 'dml' pigpen['n'] = 'dmm' pigpen['o'] = 'dmr' pigpen['p'] = 'dbl' pigpen['q'] = 'dbm' pigpen['r'] = 'dbr' pigpen['s'] = 'ext' pigpen['t'] = 'exl' pigpen['u'] = 'exr' pigpen['v'] = 'exb' pigpen['w'] = 'dxt' pigpen['x'] = 'dxl' pigpen['y'] = 'dxr' pigpen['z'] = 'dxb' import binascii str = pigpen.values() print ' '.join(format(ord(string), 'b') string in str) traceback (most recent call last): file "pigpen_build.py", line 62, in <module> print ' '.join(format(ord(string), 'b') string in str) file "pigpen_build.py", line 62, in <genexpr> print ' '.join(format(ord(string), 'b') string in str) typeerror: ord() expected character, string of length 3 found >>>
you asking ord find value based on 3 characters in string. more on the ord function here. in loop interacting on list code expanded this.
for s in ['abc','cde','fgh']: print s+', ', which output, abc, cde, fgh. fix either put loop on actual string, or combine original list 1 string.
1) loop.
print ' '.join(format(ord(string), 'b') string in (''.join(s s in str))) 2) actual string.
str = ''.join(s s in str) print ' '.join(format(ord(stirng), 'b') string in str)
Comments
Post a Comment