Answers for "input list from user"

6

get list as input

#to get integer list
integer_list = list(map(int, input().split()))
#to get char or str list, just replace int with str
str_list = list(map(str, input().split()))
#syntax of map(): map(dataType, iterable [, iterable2, iterable3,...iterableN])
Posted by: Guest on June-03-2020
1

reading a list in python

strings = list(map(str,input().split()))
numbers = list(map(int, input().split()))
Posted by: Guest on August-19-2020
0

input list from user

# number of elements
n = int(input("Enter number of elements : "))
 
# Below line read inputs from user using map() function
a = list(map(int,input("\nEnter the numbers : ").strip().split()))[:n]
 
print("\nList is - ", a)
Posted by: Guest on October-28-2021
0

input list from user

lst = [ ]
n = int(input("Enter number of elements : "))
 
for i in range(0, n):
    ele = [input(), int(input())]
    lst.append(ele)
     
print(lst)
Posted by: Guest on October-28-2021
0

input list from user

# creating an empty list
lst = []
 
# number of elements as input
n = int(input("Enter number of elements : "))
 
# iterating till the range
for i in range(0, n):
    ele = int(input())
 
    lst.append(ele) # adding the element
     
print(lst)
Posted by: Guest on October-28-2021
0

input list from user

# try block to handle the exception
try:
    my_list = []
     
    while True:
        my_list.append(int(input()))
         
# if the input is not-integer, just print the list
except:
    print(my_list)
Posted by: Guest on October-28-2021

Code answers related to "input list from user"

Python Answers by Framework

Browse Popular Code Answers by Language