implementation of some useful operations on lists like run-length
encoding method