0PricingLogin
Competitive Programming Academy · Lesson

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

  1. input() vs sys.stdin Showdown
  2. Parse Many Numbers on One Line
  3. Batch Output the Right Way
  4. Read N Lines and Edge Cases
← Back to Competitive Programming Academy