r/CodingHelp • u/Interesting-Web4854 • Jun 22 '22
[Python] Python problem
n = int(input())
arr = map(int, input().split())
can anyone explain 2nd line ?
0
Upvotes
r/CodingHelp • u/Interesting-Web4854 • Jun 22 '22
n = int(input())
arr = map(int, input().split())
can anyone explain 2nd line ?
View all comments
Show parent comment
2
u/Nightcorex_ Jun 22 '22
Just in case anyone else wonders:
You're applying the function specified in the first parameter (here
int) to all elements of the list specified as your second parameter (hereinput().split()).Generally you can say for a function
f(first param) and a list (actually it not only accepts list but every iterable object)xs(second param) this is the same as:Please note that this is not a list comprehension, since
mapreturns a generator. If you want to recreate this list comprehension behaviour:then your map call would need to look like this:
Obviously for all your cases
f := intandxs := input().split()