Given a list
old_list = [obj_1, obj_2, obj_3, ...]
I want to create a list:
new_list = [[obj_1, obj_2], [obj_3], ...]
where obj_1.some_attr == obj_2.some_attr
.
I could throw some for
loops and if
checks together, but this is ugly. Is there a pythonic way for this? by the way, the attributes of the objects are all strings.
Alternatively a solution for a list containing tuples (of the same length) instead of objects is appreciated, too.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…