def columns_have_unique_numbers_pythonic(matrix):
"""
Checks if each column of a matrix contains numbers without repetition.
Args:
matrix: A list of lists representing the matrix.
Returns:
True if all columns have unique numbers, False otherwise.
"""
if not matrix or not matrix[0]:
return True
num_cols = len(matrix[0])
for j in range(num_cols):
column = [row[j] for row in matrix] # Extract the j-th column
if len(column) != len(set(column)):
return False
return True
matrix1 = [
[1, 4, 7],
[2, 5, 8],
[3, 6, 9]
]
print(f"Matrix 1 columns have unique numbers: {columns_have_unique_numbers_pythonic(matrix1)}")
matrix2 = [
[1, 4, 7],
[2, 4, 8],
[3, 6, 9]
]
print(f"Matrix 2 columns have unique numbers: {columns_have_unique_numbers_pythonic(matrix2)}")
'''
run:
Matrix 1 columns have unique numbers: True
Matrix 2 columns have unique numbers: False
'''