Advertisement
ALEXANDAR_GEORGIEV

Multidimensional_list

May 18th, 2023
673
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.47 KB | Source Code | 0 0
  1. # Multidimensional_list
  2. # Even_matrix
  3. row = int(input())
  4.  
  5. matrix = []
  6.  
  7. for row_index in range(row):
  8.     inner_list = [int(el) for el in input().split(", ") if int(el) % 2 == 0]
  9.     matrix.append(inner_list)
  10.  
  11. print(matrix)
  12.  
  13. # Flattening_matrix
  14. row = int(input())
  15.  
  16. flatten = []
  17.  
  18. for _ in range(row):
  19.     inner_list = [int(el) for el in input().split(', ')]
  20.     flatten.extend(inner_list)
  21.  
  22.  
  23. print(flatten)
  24.  
  25. # Primary_diagonal
  26. rows = int(input())
  27.  
  28. matrix = []
  29.  
  30. for _ in range(rows):
  31.     inner_list = [int(el) for el in input().split()]
  32.     matrix.append(inner_list)
  33.  
  34. sum_diagonal = 0
  35. for index in range(rows):
  36.     sum_diagonal += matrix[index][index]
  37.  
  38. print(sum_diagonal)
  39.  
  40. # Square_with_maximum_sum
  41. rows, cols = [int(el) for el in input().split(", ")]
  42.  
  43. matrix = []
  44.  
  45. for _ in range(rows):
  46.     inner_list = [int(el) for el in input().split(", ")]
  47.     matrix.append(inner_list)
  48.  
  49.  
  50. max_sum = float('-int')
  51. sub_matrix = []
  52.  
  53. for row_index in range(rows-1):
  54.     for col_index in range(cols-1):
  55.         current_element = matrix[row_index][col_index]
  56.         element_below = matrix[row_index + 1][col_index]
  57.         next_element = matrix[row_index][col_index + 1]
  58.         diagonal_element = matrix[row_index + 1][col_index + 1]
  59.         current_sum_elements = current_element + element_below + next_element + diagonal_element
  60.  
  61.         if max_sum < current_sum_elements:
  62.             max_sum = current_sum_elements
  63.             sub_matrix = [[current_element, next_element], [element_below, diagonal_element]]
  64.  
  65. print(*sub_matrix[0])
  66. print(*sub_matrix[1])
  67. print(max_sum)
  68.  
  69. # Sum_matrix_columns
  70. rows, cols = [int(el) for el in input().split(", ")]
  71.  
  72. matrix = []
  73.  
  74. for _ in range(rows):
  75.     inner_list = [int(el) for el in input().split()]
  76.     matrix.append(inner_list)
  77.  
  78. col_sums = []
  79. for col_index in range(cols):
  80.     sum_col_elements = 0
  81.     for row_index in range(rows):
  82.         sum_col_elements += matrix[row_index][col_index]
  83.     col_sums.append(sum_col_elements)
  84.  
  85. for col_sum in col_sums:
  86.     print(col_sum)
  87.  
  88. # Sum_matrix_elements
  89. # Брой редове
  90. # брой колони
  91. # Четем данните за редове и колони
  92. rows, cols = [int(el) for el in input().split(", ")]
  93.  
  94. matrix = []
  95.  
  96.  
  97. for _ in range(rows):
  98.     inner_list = [int(el) for el in input().split(", ")]
  99.     matrix.append(inner_list)
  100.  
  101.  
  102. # Взимаме елементите от матрицата
  103. sum_nums = 0
  104. for row_index in range(rows):
  105.     for col_index in range(cols):
  106.         sum_nums += matrix[row_index][col_index]
  107.  
  108. print(sum_nums)
  109. print(matrix)
  110.  
  111. # TODO Solution 2
  112. # Четем данните за редове и колони
  113. rows, cols = [int(el) for el in input().split(", ")]
  114.  
  115. matrix = []
  116.  
  117.  
  118. for _ in range(rows):
  119.     inner_list = [int(el) for el in input().split(", ")]
  120.     sum_nums += sum(inner_list)
  121.     matrix.append(inner_list)
  122.  
  123.  
  124.  
  125. print(sum_nums)
  126. print(matrix)
  127.  
  128. # Symbol_in_matrix
  129. def find_element_in_matrix(matrix, element):
  130.     for row_index in range(n):
  131.         for col_index in range(n):
  132.             if matrix[row_index][col_index] == element:
  133.                 return (row_index, col_index)
  134.  
  135.  
  136. n = int(input())
  137.  
  138. matrix = []
  139.  
  140. for _ in range(n):
  141.     inner_list = list(input())  # List ot characters
  142.     matrix.append(inner_list)
  143.  
  144. searched_symbol = input()
  145. position = find_element_in_matrix(matrix, searched_symbol)
  146.  
  147. if position:
  148.     print(position)
  149. else:
  150.     print(f"{searched_symbol} does not occur in the matrix")
  151.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement