Thursday, October 15, 2009

P11: Modified run-length encoding that includes only repeated elements

Use unflatten method from P9 and filter it before mapping the sublist as a tuple:
println(ulist.filter(_.length > 1).map(e=>(e.length,e.head)))

Output:
List((6,'a), (2,'c), (4,'e))

No comments:

Post a Comment

Sociable