Python 2, 7373 70 bytes
A function that takes a string as input and returns a string representation of a Python list. Zero can be represented both by 0
and -0
(when it comes last):
lambda s:str(map`map(len,s.split('0')))`.replace('0, ','-').replace('--','0,')
Explanation
split
the input strings
on zeroes.- Take the length of each string in the resulting list (using
map
).
That takes us a long way. Zeroes were separators after all. And the numbers were unary, so len
conveniently converts those to decimal. But now we've messed up all the non-separator uses of 0
. Luckily, all non-separator uses were leading zeroes so they came after a separator-zero and gave us zero-length strings ('00'.split('0') == ['', '', '']
). Those zero-length strings then also became 0
because of the len
.
- Turn the list into a string (using "reverse quotes"), so we can fix up the mess more easily.
replace
each zero that precedes another number by a negative sign on that number instead. That fixes the use of0
as a sign but it breaks the literal zeroes. Literal zeroes were also preceded by a separator, so they've now become pairs of extra dashes on the next number.replace
each--
back into a0
element in the "list".