Parse Many Numbers on One Line
Split, map to int, and unpack cleanly.
One Line, Many Numbers
Contests often pack several values onto a single line, like "3 7 1 9". Your job is to turn that string into numbers you can use.
Split on Spaces
Start with .split(). With no argument it breaks the line on any whitespace and gives you a list of string pieces.
parts = input().split()All lessons in this course
- input() vs sys.stdin Showdown
- Parse Many Numbers on One Line
- Batch Output the Right Way
- Read N Lines and Edge Cases