I am facing problem to take number of inputs from user then storing it in an array,how to print this array
n = int(input())
arr = map(int, input().split())
Thanks in advance for the help
I am facing problem to take number of inputs from user then storing it in an array,how to print this array
n = int(input())
arr = map(int, input().split())
Thanks in advance for the help
In Python, map
takes a function as one argument and a list as the second argument and applies that function to all of the items in the list. The catch is that this application is lazy, meaning that it returns a map
object (which is a generator), and doesn't actually apply the function until you try to iterate through arr
.
In your case, if you want to print out the contents of arr
, you can simply do:
arr = list(map(int, input().split()))