This has not much to do with dynamic programming itself.

n, S = map(int, input().split())

will query the user for input, and then split it into words, convert these words in integers, and unpack it into two variables n and S. This thus will succeed when the user enters two numbers (not more, not less).

It works as follows:

  1. input() will query the user for input, and read one line of user input;
  2. .split() will split that input into a list of "words";
  3. map(int, ...) will call int on each word, it will to that lazily (although that is not important here); and
  4. n, S = ... will unpack the expression into two elements, and assign the first one to n and the second one to S.

For example:

>>> n, S = map(int, input().split())
14 25
>>> n
14
>>> S
25

But it will error if you pass only one number, three numbers, etc. like:

>>> n, S = map(int, input().split())
14
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: not enough values to unpack (expected 2, got 1)
>>> n, S = map(int, input().split())
14 25 37
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: too many values to unpack (expected 2)
>>> n, S = map(int, input().split())
foo bar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'foo'

The line:

w = list(map(int, input().split()))

does more or less the same thing, but instead takes as input from the user a sequence of numbers. There can be zero, one or more numbers. w will store a list of numbers. The list(..) part forces Python to evaluate the map(..) eagerly.

dp = [0] * (S + 1)

Here we will construct a list with S + 1 zeros. In Python, you can multiply a list (and tuple) with an integer n. The result is a list (or tuple) that is n times as large as the original list, and it repeats the elements. For example:

>>> [1,4,2,5] * 3
[1, 4, 2, 5, 1, 4, 2, 5, 1, 4, 2, 5]

Since here the given list contains one zero, it will thus produce a list that contains S+1 zeros.

Finally

dp[0] = 0

will set the first element to zero. But since that was already the case, this line is not very useful.

Answer from willeM_ Van Onsem on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › input-multiple-values-user-one-line-python
How to input multiple values from user in one line in Python? - GeeksforGeeks
July 23, 2025 - Explanation: input().split() reads space-separated values and stores them as strings in a list a. The for loop converts each string to an integer and updates the list in place.
🌐
Reddit
reddit.com › r/learnpython › what does list(map(int,input().split())) do in python?
r/learnpython on Reddit: What does list(map(int,input().split())) do in python?
September 15, 2020 -

What does list(map(int,input().split())) do in python? Can please anyone explain what this line does.

Python list() vs split() Apr 22, 2021
r/AskProgramming
5y ago
Explaining Split function Nov 25, 2021
r/learnpython
4y ago
More results from reddit.com
🌐
Stack Overflow
stackoverflow.com › questions › 17121706 › using-mapint-raw-input-split
python - using map(int, raw_input().split()) - Stack Overflow
Though I like python very much, When I need to get multiple integer inputs in the same line, I prefer C/C++. If I use python, I use: a = map(int, raw_input().split()) Is this the only way or is th...
🌐
Brainly
brainly.com › engineering › college › what does `map(int, input().split())` do in python?
[FREE] What does `map(int, input().split())` do in Python? - brainly.com
November 2, 2023 - The expression map(int, input().split()) in Python reads a line of user input, splits it into substrings, and converts each substring into an integer using the map function. The result is a map object that contains these integers.
Top answer
1 of 1
6

This has not much to do with dynamic programming itself.

n, S = map(int, input().split())

will query the user for input, and then split it into words, convert these words in integers, and unpack it into two variables n and S. This thus will succeed when the user enters two numbers (not more, not less).

It works as follows:

  1. input() will query the user for input, and read one line of user input;
  2. .split() will split that input into a list of "words";
  3. map(int, ...) will call int on each word, it will to that lazily (although that is not important here); and
  4. n, S = ... will unpack the expression into two elements, and assign the first one to n and the second one to S.

For example:

>>> n, S = map(int, input().split())
14 25
>>> n
14
>>> S
25

But it will error if you pass only one number, three numbers, etc. like:

>>> n, S = map(int, input().split())
14
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: not enough values to unpack (expected 2, got 1)
>>> n, S = map(int, input().split())
14 25 37
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: too many values to unpack (expected 2)
>>> n, S = map(int, input().split())
foo bar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'foo'

The line:

w = list(map(int, input().split()))

does more or less the same thing, but instead takes as input from the user a sequence of numbers. There can be zero, one or more numbers. w will store a list of numbers. The list(..) part forces Python to evaluate the map(..) eagerly.

dp = [0] * (S + 1)

Here we will construct a list with S + 1 zeros. In Python, you can multiply a list (and tuple) with an integer n. The result is a list (or tuple) that is n times as large as the original list, and it repeats the elements. For example:

>>> [1,4,2,5] * 3
[1, 4, 2, 5, 1, 4, 2, 5, 1, 4, 2, 5]

Since here the given list contains one zero, it will thus produce a list that contains S+1 zeros.

Finally

dp[0] = 0

will set the first element to zero. But since that was already the case, this line is not very useful.

🌐
Reddit
reddit.com › r/learnpython › arr = map(int, input().split())
r/learnpython on Reddit: arr = map(int, input().split())
May 11, 2019 -

I am creating a dynamic array using the following code: (PYTHON 3)

arr = map(int, input().split())
print(arr)

I am actually trying to print the array. But the print statement is returning a value as:

<map object at 0x00000265D78A4400>

I want to print the array and also access each element separately. How can I implement that ?

I am a new python learner need some help....

Thank you

🌐
EyeHunts
tutorial.eyehunts.com › home › map input split python | example code
Map input split Python | Example code
July 31, 2023 - input_data = list(range(1, 101)) # Sample input data from 1 to 100 split_size = 10 # Size of each input split input_splits = generate_input_splits(input_data, split_size) for split in input_splits: # Process each split using your mapper function or any other processing logic print("Processing input split:", split) # Your mapper logic here... Comment if you have any doubts or suggestions on this Python input code. ... All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
🌐
Quora
quora.com › How-does-this-line-work-Map-int-input-split
How does this line work: Map (int, input().split())? - Quora
Answer: A2A: I take this as a Python 3 question. [code ]input()[/code] returns a string typed in at the command line. [code ].split()[/code], applied to a string, returns a list consisting of whitespace-free substrings that had been separated by whitespace. [code ]map[/code] transform the list...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › taking-multiple-inputs-from-user-in-python
Taking multiple inputs from user in Python - GeeksforGeeks
June 26, 2026 - Let's take a look at other cases of taking multiple inputs from user in python: map() is useful when multiple inputs need to be converted to a specific data type, such as integers or floats.
🌐
Medium
medium.com › @busranurok › python-da-map-int-input-split-nasıl-kullanılır-10138d211655
Python’ da map(int, input().split()) Nasıl Kullanılır? | by Büşra Nur OK | Medium
July 5, 2023 - Kullanıcıdan bir satırda birden fazla girdi almak için map() fonksiyonu kullanırız. İlk olarak .input(), kullanıcıyı girdi için sorgularız ve kullanıcı girdisinin bir satırını okuruz.
🌐
Medium
maria13.medium.com › how-to-use-split-method-map-function-and-for-loop-in-python-ef86adbfba2d
How to use split() method, map() function and for loop in Python | by Maria Ugnich | Medium
January 5, 2021 - Python also has a way to swap the value of two variables by using = operator. Example: x = 2 y = 3x, y = y, xprint(x) print(y)#output: 3 2 · A for loop is used to iterate over elements of a sequence. Statement below is how for loop usually works. If i is element in a list, do: Example · arr = list(map(int, input().split()))max = arr[0] min = arr[0]for i in range(0, len(arr)): if max < arr[i]: max = arr[i] elif min > arr[i]: min = arr[i] max, min = min, maxprint(max) print(min) Explanation: First, ask the user to type some numbers.
Top answer
1 of 2
4
  • map(function, iterable) Return an iterator that applies function to every item of iterable, yielding the results.
  • int(x) Return an integer object constructed from a number or string x.

Therefore, it will return an iterable where it applied the int() function to each substring from .split(), meaning it casts every substring to int.

Example:

arr = map(int, "12 34 56".split())
arr = list(arr) # to convert the iterable to a list
print(arr) # prints: [12, 34, 56]

# This is equivalent:
arr = [int("12"), int("34"), int("56")]

Other example with custom function instead of int():

def increment(x):
    return x + 1

arr = map(increment, [1, 2, 3, 4, 5])
arr = list(arr)
print(arr) # prints: [2, 3, 4, 5, 6]
2 of 2
3

Let's say I type 5 and then enter at the first prompt:

n = int(input())

Would take the input "5" and make it into the integer 5. So we are going from a string to an int

Then we will get another input prompt because we have input() again in the next line: This time I'll type 123 324 541 123 134 and then enter.

the .split() will split this into "123", "324", "541", "123", "134" which is a list (well a map) of strings. Then we'll map int onto them to give ourselves a map of ints rather than strings. int converts the strings to integers.

When checking out code it is often helpful to try things in a REPL (read execute print, looper). In your command promt just type python or python3 if you have it installed or use replt.it. Type a = "123" + "321" then try `a = int("123") + int("321")

Wrap this with list(map(int, input().split())) to get a list rather than a map.

🌐
EyeHunts
tutorial.eyehunts.com › home › how to take space-separated integer input in python 3 | example code
How to take space-separated integer input in Python 3 | Example
May 19, 2023 - print("Enter the numbers: ") inp = list(map(int, input().split())) print(inp) ... # Take space-separated integer input from the user input_string = input("Enter space-separated integers: ") # Split the input string into individual elements ...
🌐
w3resource
w3resource.com › python-exercises › python-basic-exercise-134.php
Python: Input two integers in a single line - w3resource
... # Print a message to instruct the user to input the values of 'x' and 'y'. print("Input the value of x & y") # Use 'map' to apply the 'int' function to the input values and split them into variables 'x' and 'y'. x, y = map(int, input().split()) ...
🌐
myCompiler
mycompiler.io › view › ILin3G1JVhp
map(int, input().split()) (Python) - myCompiler
September 13, 2025 - a = input() print(a) b = input().split() print(b) c, d = input().split() print(c) print(d) print(type(c)) print(type(d)) c = int(c) d = int(d) f, g = map(int, input().split()) print(f) print(g) print(type(f)) print(type(g))
Published: Sep 06, 2025
🌐
freeCodeCamp
forum.freecodecamp.org › freecodecamp contributors
A Guide to the Python Input() Function - freeCodeCamp Contributors - The freeCodeCamp Forum
June 30, 2026 - Sometimes in your program you may want some input from the user. This makes the program feel more interactive and versatile to use. In Python 3, to receive input from the user, we use input() . When the input function is called, the program flow will stop until the user has given an input and has ended the input with the return key.
🌐
Stack Overflow
stackoverflow.com › questions › 75685862 › can-you-explain-what-is-this-l-listmapint-input-split
python - Can you explain what is this? l=list(map(int,input().split())) - Stack Overflow
So it goes something like this: ... map(int, split_list) takes a function to execute int on each element in the list and returns a new iterator (it doesn't run the function immediately, it's like lazy loading)