With a string and a binary list of the same length, for example:
[0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0]
s t a c k o v e r f l o w
Is it possible to obtain a new string as -t-c-over---- that follows:
[0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0]
- t - c - o v e r - - - -
That is, each character matching with 0 will be replaced as -. The desired output would be a list as below with letters matching 1 and hyphens matching 0 are grouped separately:
['-', 't', '-', 'c', '-', 'over', '----']
Thanks!
1would be trivial but I have trouble replacing0.zip, right?zipyour string and binary list together? And then do, say, aforloop iterating over the result?