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:47:22 EDT 2019


Às 22:21 de 21/04/19, Paul Rubin escreveu:
> Paulo da Silva <p_s_d_a_s_i_l_v_a_ns at netcabo.pt> writes:
>> splitter={}
>> for f in Objs:
>> 	splitter.setdefault(f.getId1,[]).append(f)
>> groups=[gs for gs in splitter.values() if len(gs)>1]
> 
> It's easiest if you can sort the input list and then use
> itertools.groupby.
Yes, sort and groupby seems the best way to go.
Thanks.


More information about the Python-list mailing list