Better ways for implementing two situations

Paulo da Silva p_s_d_a_s_i_l_v_a_ns at netcabo.pt
Tue Apr 23 12:37:05 EDT 2019


Às 19:42 de 21/04/19, Stefan Ram escreveu:
> Paulo da Silva writes:
>> I have a list of objects and want to split it in a list of groups.
>> "equal objects" is based on an id we can get from the object.
> 
>   main.py
> 
> input = [ 'abc', 'ade', 'bcd' ]
> 
> for group, list in \
> __import__( 'itertools' ).groupby( input, lambda x: x[ 0 ] ):
>     print( group, *list )
> 

Yes, seems to be the best way to go. I need to sort data first, however.

Thanks



More information about the Python-list mailing list