タプルの長いリストを生成しました (以下の形式)。リスト内の各タプルは、最初の要素として時間を持ち、3 番目のメンバーとしてイベントを持ちます。2 番目のメンバーは常に同じで、対処しなければならない他の同様のリストからリストを識別します。タプルには多くの異なる 3 番目の要素があり、それぞれが最初の要素である時間の異なる値で複数のエントリを持っています。
リストをフィルタリングして、各イベント (タプルの 3 番目のメンバー) の時間の最小値と最大値 (タプルの最初の項目) を除くすべてを削除しようとしています。リスト内包表記を使用してみましたが、すぐに混乱してしまいました。
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP1_G1.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP1_G1.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP1_G1.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP1_G1.575')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3567', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3600', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3800', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3800', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3800', 'VOLTAGE DEVIATION', 'HORIZ_G .575')
('1.3800', 'VOLTAGE DEVIATION', 'MEDBOWCO 115')
('1.3800', 'VOLTAGE DEVIATION', 'MEDBOWCO 115')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS 34.5')
'1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4267', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4267', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4267', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4267', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4267', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4833', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4833', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4833', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4833', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4833', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
フィルタ後の結果は
('1.3433', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP2G23.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP1_G1.575')
('1.3467', 'VOLTAGE DEVIATION', 'DNLP1_G1.575')
('1.3533', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3600', 'VOLTAGE DEVIATION', 'DIFICULT 230')
('1.3600', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3800', 'VOLTAGE DEVIATION', '7MIHL G1.575')
('1.3800', 'VOLTAGE DEVIATION', 'HORIZ_G .575')
('1.3800', 'VOLTAGE DEVIATION', 'MEDBOWCO 115')
('1.3800', 'VOLTAGE DEVIATION', 'MEDBOWCO 115')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3800', 'VOLTAGE DEVIATION', 'STNDPSVC 230')
('1.3867', 'VOLTAGE DEVIATION', 'MINERS 34.5')
('1.3900', 'VOLTAGE DEVIATION', 'MINERS 34.5')
'1.4233', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4267', 'VOLTAGE DEVIATION', 'FT CRK2 34.5')
('1.4800', 'VOLTAGE DEVIATION', 'HIPLN_G .575')
('1.4833', 'VOLTAGE DEVIATION', 'HIPLN_G .575')`
以下のコードを試していますが、エラーが発生します。私はこれにかなり慣れていないので、間違ったことをしている場合は教えてください。コード内の m1 は、findall から生成されたタプルのリストです。コードの先頭に ast をインポートしました。
m1 = re.findall(pattern1,wholefile)
m1=[ast.literal_eval(t) for t in m1]
m1=[(float(a),b,c) for a,b,c in m1]
keys=sorted({t[2] for t in m1})
for key in keys:
group=filter(lambda t: t[2]==key,m1)
print '{}:\n\tmax: {}\n\tmin: {}'.format(key,max(group),min(group))