Python: form a list based on the same values -
consider x = [10,10,20,20,20,30] how form list_x1 contains same values example: list_x1 = [10,10] , list_x2 =[20,20] , list_x3 =[30] ?
with itertools.groupby
>>> itertools import groupby >>> x = [10,10,20,20,20,30] >>> [list(g) k, g in groupby(x)] [[10, 10], [20, 20, 20], [30]]
Comments
Post a Comment