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

Popular posts from this blog

How to check data type in C++? -

javascript - Is getTimezoneOffset() stable during daylight saving transition? -

sql server - SQL Query returns one result, does not return 0 or NULL result -