-2

When I'm trying to print matrix1, the output is the memory address of the object.

print("enter n for nxn matrix")
n = int(input())

matrix1 = []
matrix2 = []

#taking elements of first matrix

print("Enter elements of first matrix")
for i in range(0,n):

  #taking elements of first column

  print("Enter elements of ",i,"column, seperated by space")

  #raw_input().split() will split the string
  #'1 2 34'.split() will give ['1', '2', '34']
  #map will convert its elements into integers [1, 2, 34]

  matrix1.append(map(int,input().split()))

print("Matrix 1 is",matrix1)
print(matrix1)

Ouput recieved.

enter n for nxn matrix
2
Enter elements of first matrix
Enter elements of  0 column, seperated by space
2 3
Enter elements of  1 column, seperated by space
4 5
Matrix 1 is [<map object at 0x101834898>, <map object at 0x1032d2f60>]

Not sure why the memory address of the object is being printed. I'm using python3.

1 Answers1

0

map returns itself (or perhaps it is better to say it returns an object of its type?) but you can still iterate through it:

j = [1, 2, 3, 4]
j = map(lambda x: x+1, j)
{x for x in j}

Gives:

{2, 3, 4, 5}
Charles Landau
  • 4,187
  • 1
  • 8
  • 24