-1
        a,y = map(int, input().split())
    scores = [map(float, input().split()) for _ in range(y)]
    
    [print(sum(student)/y) for student in zip(*scores)]

this code is supposed to take inputs : no. of students, no. of subjects and marks scored in each one of them and then give average of all students. i have two questions:

  • how is map() method able to take 2 variables i am new to programming so as far as i know to give values to multiple variables at the same time you need to separate them with commas(not done in the above situation) how does that work.
  • how is there a variable student in the code when it is not even defined and still works perfectly?

this code was a solution to a beginnner level problem in hackerrank

  • [Answer to question 1](https://stackoverflow.com/questions/34308337/unpack-list-to-variables) is "unpacking" – Cory Kramer Oct 27 '21 at 17:27
  • [Answer to question 2](https://stackoverflow.com/questions/34835951/what-does-list-comprehension-mean-how-does-it-work-and-how-can-i-use-it) is "list comprehension" – Cory Kramer Oct 27 '21 at 17:27
  • Though my general advice is to learn Python from an introductory tutorial, not from reading/writing code snippets on hackerrank or leetcode – Cory Kramer Oct 27 '21 at 17:29
  • your answer was indeed informative but it did not answer the question – EXPLICIT GAMING Oct 27 '21 at 17:43
  • Both of your questions were basically "how does this work", and are explained in detail in each of the respective links. – Cory Kramer Oct 27 '21 at 17:48

1 Answers1

0

The syntax in the first line is only valid if the map reads a pair of input, then the first input will be stored in the first variable and the second input will be stored in the second one. Else, it will give an error.

Yashasvi
  • 36
  • 3