Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- lines = sorted(list(open('coll_2019-03-18_16_43_01.txt','r',encoding='utf-8'))[5:])
- lines = [line.split() for line in lines] # разделяем на элементы
- lines = [line for line in lines if len(line) > 0] #фильтруем пустные
- groups = [[lines[0]]] #инициализируем группы
- def comp(a, b): # сравниваем элементы
- return (len(a) == len(b)) and (a[:3] == b[:3])
- def max_for_n(items, n): #получаем максимальный n-ый элемент из группы
- values = [float(i[n]) for i in items]
- return max(values)
- for line in lines[1:]:
- last_group = groups[-1]
- last_word = last_group[0][0]
- current_word = line[0]
- if comp(current_word, last_word):
- last_group.append(line)
- else:
- groups.append([line])
- result = []
- for group in groups:
- first_line = group[0]
- for i in range(1, len(first_line)):
- first_line[i] = max_for_n(group, i)
- result.append(first_line)
- for g in result:
- print(g)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement