'How to convert binary into sign representation?

If an array consist of decimal number which represents as blocks('#') or empty(' '). For example.

A = [31,21,29,19,31]
represents
['11111', '10101', '11101', '10011', '11111']

and I want to have this array to be like this
['#####', '# # #', '### #', '# ##', '#####']



Solution 1:[1]

You can use a list comprehension with string formatting (here a f-string) and a translation table:

A = [31,21,29,19,31]  

trans = str.maketrans('01', ' #')
# {48: 32, 49: 35}

out = [f'{x:b}'.translate(trans) for x in A]

output:

['#####', '# # #', '### #', '#  ##', '#####']

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1