Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Multidimensional_list
- # Even_matrix
- row = int(input())
- matrix = []
- for row_index in range(row):
- inner_list = [int(el) for el in input().split(", ") if int(el) % 2 == 0]
- matrix.append(inner_list)
- print(matrix)
- # Flattening_matrix
- row = int(input())
- flatten = []
- for _ in range(row):
- inner_list = [int(el) for el in input().split(', ')]
- flatten.extend(inner_list)
- print(flatten)
- # Primary_diagonal
- rows = int(input())
- matrix = []
- for _ in range(rows):
- inner_list = [int(el) for el in input().split()]
- matrix.append(inner_list)
- sum_diagonal = 0
- for index in range(rows):
- sum_diagonal += matrix[index][index]
- print(sum_diagonal)
- # Square_with_maximum_sum
- rows, cols = [int(el) for el in input().split(", ")]
- matrix = []
- for _ in range(rows):
- inner_list = [int(el) for el in input().split(", ")]
- matrix.append(inner_list)
- max_sum = float('-int')
- sub_matrix = []
- for row_index in range(rows-1):
- for col_index in range(cols-1):
- current_element = matrix[row_index][col_index]
- element_below = matrix[row_index + 1][col_index]
- next_element = matrix[row_index][col_index + 1]
- diagonal_element = matrix[row_index + 1][col_index + 1]
- current_sum_elements = current_element + element_below + next_element + diagonal_element
- if max_sum < current_sum_elements:
- max_sum = current_sum_elements
- sub_matrix = [[current_element, next_element], [element_below, diagonal_element]]
- print(*sub_matrix[0])
- print(*sub_matrix[1])
- print(max_sum)
- # Sum_matrix_columns
- rows, cols = [int(el) for el in input().split(", ")]
- matrix = []
- for _ in range(rows):
- inner_list = [int(el) for el in input().split()]
- matrix.append(inner_list)
- col_sums = []
- for col_index in range(cols):
- sum_col_elements = 0
- for row_index in range(rows):
- sum_col_elements += matrix[row_index][col_index]
- col_sums.append(sum_col_elements)
- for col_sum in col_sums:
- print(col_sum)
- # Sum_matrix_elements
- # Брой редове
- # брой колони
- # Четем данните за редове и колони
- rows, cols = [int(el) for el in input().split(", ")]
- matrix = []
- for _ in range(rows):
- inner_list = [int(el) for el in input().split(", ")]
- matrix.append(inner_list)
- # Взимаме елементите от матрицата
- sum_nums = 0
- for row_index in range(rows):
- for col_index in range(cols):
- sum_nums += matrix[row_index][col_index]
- print(sum_nums)
- print(matrix)
- # TODO Solution 2
- # Четем данните за редове и колони
- rows, cols = [int(el) for el in input().split(", ")]
- matrix = []
- for _ in range(rows):
- inner_list = [int(el) for el in input().split(", ")]
- sum_nums += sum(inner_list)
- matrix.append(inner_list)
- print(sum_nums)
- print(matrix)
- # Symbol_in_matrix
- def find_element_in_matrix(matrix, element):
- for row_index in range(n):
- for col_index in range(n):
- if matrix[row_index][col_index] == element:
- return (row_index, col_index)
- n = int(input())
- matrix = []
- for _ in range(n):
- inner_list = list(input()) # List ot characters
- matrix.append(inner_list)
- searched_symbol = input()
- position = find_element_in_matrix(matrix, searched_symbol)
- if position:
- print(position)
- else:
- print(f"{searched_symbol} does not occur in the matrix")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement