Advertisement
Gamerkin

ex10 kispython

May 10th, 2024
661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | None | 0 0
  1. def remove_empty_columns(table):
  2.     empty_columns = [i for i in range(len(table[0])) if all(row[i] is None for
  3.                                                             row in table)]
  4.     for i in reversed(empty_columns):
  5.         for row in table:
  6.             del row[i]
  7.  
  8.  
  9. def remove_duplicates(table):
  10.     unique_rows = set()
  11.     unique_rows_ordered = []
  12.     for row in table:
  13.         if tuple(row) not in unique_rows:
  14.             unique_rows_ordered.append(row)
  15.             unique_rows.add(tuple(row))
  16.     table.clear()
  17.     table.extend(unique_rows_ordered)
  18.  
  19.  
  20. def remove_empty_rows(table):
  21.     table[:] = [row for row in table if any(cell is not None for cell in row)]
  22.  
  23.  
  24. def convert_cell(cell):
  25.     if cell == 'Выполнено':
  26.         return "1"
  27.     elif cell == 'Не выполнено':
  28.         return "0"
  29.     elif cell is not None and '[at]' in cell:
  30.         return cell.split('[at]')[0]
  31.     else:
  32.         return "{:.3f}".format(float(cell))
  33.  
  34.  
  35. def convert_cells(table):
  36.     # Преобразуем содержимое ячеек
  37.     for row in table:
  38.         row[:] = [convert_cell(cell) for cell in row]
  39.  
  40.  
  41. def sort_by_column(table, column):
  42.     table.sort(key=lambda x: x[column])
  43.  
  44.  
  45. def transpose_matrix(matrix):
  46.     transposed = list(zip(*matrix))
  47.     return transposed
  48.  
  49.  
  50. def main(input_table):
  51.     table = [list(row) for row in input_table]
  52.  
  53.     remove_empty_columns(table)
  54.     remove_duplicates(table)
  55.     remove_empty_rows(table)
  56.     convert_cells(table)
  57.     sort_by_column(table, 2)
  58.     table = list(map(list, zip(*table)))
  59.     return table
  60.  
  61.  
  62. input_table_1 = [
  63.     [None, None, None, None],
  64.     ['Выполнено', '0.7', None, 'cererman34[at]gmail.com'],
  65.     [None, None, None, None],
  66.     ['Не выполнено', '0.0', None, 'rivonberg24[at]gmail.com'],
  67.     ['Не выполнено', '0.3', None, 'zicimic42[at]yahoo.com'],
  68.     ['Не выполнено', '0.3', None, 'zicimic42[at]yahoo.com'],
  69.     ['Выполнено', '0.5', None, 'aleksandr37[at]yandex.ru']
  70. ]
  71.  
  72. output_table_1 = main(input_table_1)
  73. print(output_table_1)
  74.  
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement