Monday, October 27, 2008

99 problems - python - 12

Decode a run-length encoded list. Given a run-length code list generated as specified in problem 11. Construct its uncompressed version.

def decode(encoded):
for x in encoded:
if type(x) == tuple:
for _x in range(x[0]):
yield x[1]
else:
yield x

By now you should know to throw a "list" into the mix if that's the way you swing.

No comments: