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

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -