Get a list as input from user in Python
We often encounter a situation when we need to take a number/string as input from the user. In this article, we will see how to get input a list from the user using Python.
Example:
Input : n = 4, ele = 1 2 3 4
Output : [1, 2, 3, 4]
Input : n = 6, ele = 3 4 1 7 9 6
Output : [3, 4, 1, 7, 9, 6]
Get a list as input from user in Python using Loop
Python3
|
Output:
Time Complexity: O(n), where n is the length of the list
Auxiliary Space: O(n) additional space of size n is created where n is the number of elements in the list
Get a list as input from user in Python With exception handling
Python3
|
Output:
Get a list as input from user in Python Using map()
Python3
|
Output:
Get a list as input from user in Python List of lists as input
Python3
|
Output:
Python3
|
Output:
Last Updated :
28 Aug, 2023
Like Article
Save Article