0

Hi I want to know how *map works here:

Fraction(*map(int, input().split()))

I understood that it returns the parameters to the outer function - (Fraction) here.

But I also tried some thing like this -

List(*map(int, input().split()))

and

sum(*map(int, input().split()))

Its not working.

So I am not sure what actually *map returns. Need help on this! Thanks!

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 2
    `*` spreads the result of `map()` into separate arguments to the function. But `list` and `sum` don't expect multiple arguments. They expect a single argument containing the sequence to iterate over. – Barmar Mar 03 '22 at 01:54
  • 1
    When you say "Its not working." you always should tell us *exactly what isn't working* – juanpa.arrivillaga Mar 03 '22 at 01:55
  • map returns a map object. You need to convert it to list so that you can pass it to sum. `sum(list(map(int,input().split())))` – balu Mar 03 '22 at 04:52

0 Answers0