Answers for "read a list in python"

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
7

how to get user input of list in python

# 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 May-04-2020
11

python get element from list

my_list = ["pizza", "soda", "muffins"]

my_list[0] # outputs "pizza"
my_list[-1] # outputs the last element of the list which is "muffins"
my_list[:] # outputs the whole list
my_list[:-1] # outputs the whole list except its last element

# you can also access a string's letter like this
Posted by: Guest on June-07-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
1

how to get user input of list of lists in python

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 May-04-2020

Python Answers by Framework

Browse Popular Code Answers by Language