Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私は次のようなリストを持っています
A= [(1,0,10),(1,10,20), (1,20,30), (2,5,25), (2,5,50), (2,50,100)]
A の各タプルの最初のメンバー、次に各グループの最小値と最大値に基づいてグループ化する必要があります。出来上がりはこんな感じ
B = [(1,0,30),(2,5,100)]
>>> from operator import itemgetter >>> from itertools import groupby def solve(lis): for k, g in groupby(lis, key=itemgetter(0)): lis = [y for x in g for y in x[1:]] yield (k, min(lis), max(lis)) ... >>> list(solve(A)) [(1, 0, 30), (2, 5, 100)]