Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def remove_empty_columns(table):
- empty_columns = [i for i in range(len(table[0])) if all(row[i] is None for
- row in table)]
- for i in reversed(empty_columns):
- for row in table:
- del row[i]
- def remove_duplicates(table):
- unique_rows = set()
- unique_rows_ordered = []
- for row in table:
- if tuple(row) not in unique_rows:
- unique_rows_ordered.append(row)
- unique_rows.add(tuple(row))
- table.clear()
- table.extend(unique_rows_ordered)
- def remove_empty_rows(table):
- table[:] = [row for row in table if any(cell is not None for cell in row)]
- def convert_cell(cell):
- if cell == 'Выполнено':
- return "1"
- elif cell == 'Не выполнено':
- return "0"
- elif cell is not None and '[at]' in cell:
- return cell.split('[at]')[0]
- else:
- return "{:.3f}".format(float(cell))
- def convert_cells(table):
- # Преобразуем содержимое ячеек
- for row in table:
- row[:] = [convert_cell(cell) for cell in row]
- def sort_by_column(table, column):
- table.sort(key=lambda x: x[column])
- def transpose_matrix(matrix):
- transposed = list(zip(*matrix))
- return transposed
- def main(input_table):
- table = [list(row) for row in input_table]
- remove_empty_columns(table)
- remove_duplicates(table)
- remove_empty_rows(table)
- convert_cells(table)
- sort_by_column(table, 2)
- table = list(map(list, zip(*table)))
- return table
- input_table_1 = [
- [None, None, None, None],
- ['Выполнено', '0.7', None, 'cererman34[at]gmail.com'],
- [None, None, None, None],
- ['Не выполнено', '0.0', None, 'rivonberg24[at]gmail.com'],
- ['Не выполнено', '0.3', None, 'zicimic42[at]yahoo.com'],
- ['Не выполнено', '0.3', None, 'zicimic42[at]yahoo.com'],
- ['Выполнено', '0.5', None, 'aleksandr37[at]yandex.ru']
- ]
- output_table_1 = main(input_table_1)
- print(output_table_1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement