4
if __name__ == '__main__':
    n = int(input())
    student_marks = {}
    for _ in range(n):
        name, *line = input().split()
        scores = list(map(float, line))
        student_marks[name] = scores
    query_name = input()

Can someone explain the use of * in the above Python snippet?

Corentin Pane
  • 4,794
  • 1
  • 12
  • 29
Ruban
  • 125
  • 7

2 Answers2

7

That's called unpacking. It puts the first item in name and all other items in a list called line.

name, *line = [1, 2, 3, 4]
print(name) #1
print(line) #[2, 3, 4]
Corentin Pane
  • 4,794
  • 1
  • 12
  • 29
2

In this case, the name variable holds first element that input.().split() returns, by using *line everything after first element is holded by line variable.

dannyxn
  • 422
  • 4
  • 16