0

I've got 2 bidimensional arrays in python, and I must print like results of the common elements between those list.

I have tried to solve this with intersetion function but I didn't get any result. Any ideas? Thanks a lot!

fila= int(input("Digite el numero de filas "))
columna=int(input("Digite el numero de columnas "))
matriz=[]
for i in range(fila):
    matriz.append([])
    for j in range(columna):
        valor= int(input(f"Digite el valor {i} {j} de la matriz: "))
        matriz[i].append(valor)
        #La función sort(revers=True) utiliza el algoritmo BubleSort para ordenar
        #en forma descendente
        matriz[i].sort(reverse=True)
print("\nLas primera matiz ingresada, en orden decreciente es: ")
print(matriz)
#Ahora inicializamos un arreglo que equivale a la segunda matriz a trabajar
fila_2= int(input("Digite el numero de filas "))
columna_2=int(input("Digite el numero de columnas "))
matriz_2=[]
for i in range(fila_2):
    matriz_2.append([])
    for j in range(columna_2):
        valor= int(input(f"Digite el valor {i} {j} de la matriz: "))
        matriz_2[i].append(valor)
        #La función sort(revers=True) utiliza el algoritmo BubleSort para ordenar
        #en forma descendente
        matriz_2[i].sort(reverse=True)
      
print("\nLas segunda matiz ingresada, en orden decreciente es: ")
print(matriz_2)
z = matriz.intersection(matriz_2)
print("\nLos elementos comunes en ambas matrices son: ")
print (z)
Michael M.
  • 10,486
  • 9
  • 18
  • 34
  • https://stackoverflow.com/questions/3697432/how-to-find-list-intersection/3697438#3697438 – gapsf Oct 08 '22 at 18:58

0 Answers0