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
🌐
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.

Explaining Split function Nov 25, 2021
r/learnpython
4y ago
Difference between list() and [] Jan 19, 2022
r/learnpython
4y ago
Python list() vs split() Apr 22, 2021
r/AskProgramming
5y ago
More results from reddit.com
🌐
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 - For instance, if a user enters '4 5 6', using list(map(int, input().split())) will give you a list of integers: [4, 5, 6]. This behavior is well-documented in Python's official documentation, confirming how the input, split, and map functions ...
🌐
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: When the user enters ... a list of strings like ["10", "20", "30"]. map(int, ...) converts each string to an integer and list() turns the result into a list of 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

🌐
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. ... A for loop is used to iterate over elements of a sequence. Statement below is how for loop usually works. ... 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)
🌐
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)
🌐
EyeHunts
tutorial.eyehunts.com › home › map input split python | example code
Map input split Python | Example code
July 31, 2023 - A simple example code reads two numbers from input and typecasts them to int using the map function in Python. x, y = map(int, input("Enter 2 number with space: ").split()) print("First Number: ", x) print("Second Number: ", y)
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › taking-multiple-inputs-from-user-in-python
Taking multiple inputs from user in Python - GeeksforGeeks
June 26, 2026 - One of the simplest ways to take multiple inputs from a user in Python is by using the input() function along with the split() method. The split() method splits a string into a list based on a specified separator (by default, it uses whitespace).
🌐
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...
🌐
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...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-get-a-list-as-input-from-user
Get a list as input from user in Python - GeeksforGeeks
In Python, getting a list as input ... in a Python list data structure. input() function can be combined with split() to accept multiple elements in a single line and store them in a list....
Published: September 18, 2025
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-integers-string-to-integer-list
Python - Integers String to Integer List - GeeksforGeeks
July 15, 2025 - s = "1 2 3 4 5" # Convert the string to a list of integers using split and map int_list = list(map(int, s.split())) print(int_list) ... The split() method splits the input string s into individual string elements based on spaces.
🌐
RS Blog
reneshbedre.com › blog › split-string-into-int-list-python.html
How to split strings into a list of integers in Python?
December 12, 2022 - # input string s = '12 34 55 66 88 78' # convert string into list of int int_list = list(map(int, s.split())) # output [12, 34, 55, 66, 88, 78]
🌐
Stack Overflow
stackoverflow.com › questions › 60933507 › why-to-use-listmapstr-input-split-when-input-split-is-already-li
python 3.x - why to use `list(map(str,input().split()))` when `input().split()` is already list - Stack Overflow
input().split() i need to convert this into list of strings both works but... what is the difference? Is list(map()) unneeded here ? python-3.x · string · list · input · Share · Share a link to this question · Copy linkCC BY-SA 4.0 · Short permalink to this question ·
🌐
Quora
quora.com › What-does-the-following-line-mean-in-Python-list-map-int-input-split
What does the following line mean in Python list=map (int, input().split())? - Quora
Answer (1 of 3): Let’s understand this step by step. In Python, input() function reads a line from input (usually user), convert a line into string and returns it. Split() method returns a list of strings after breaking given string using specific separator.
🌐
Medium
kkbhoyar.medium.com › inputting-with-python-input-statement-for-beginners-8933b4fa37c6
Inputting with Python input statement for Beginners | by Dr. Kishor Bhoyar | Medium
July 26, 2020 - An iterable is any Python object ... element of the given iterable. The split() function separates input line entered by the user into a list of different tokens separated by the given separator....
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-split-a-list-having-single-integer
Split a List having Single Integer - Python - GeeksforGeeks
July 11, 2025 - Let's explore some more ways and see how we can split a list having single integer in Python. ... # Initializing list a = [12345] # Splitting the integer using map() result = list(map(int, str(a[0]))) print(result)