I tried to use raw_input()
to get a list of numbers, however with the code
numbers = raw_input()
print len(numbers)
the input
In Python 3 :
input_list = [int(x.strip()) for x in input("enter list:").strip()[1:-1].split(",")]
It will ask to "enter list" so just enter list like [2,4,5]
(common_py3) PS E:\virtual_env_all\common_py3\Scripts> python
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 16:07:46) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> input_list = [int(x.strip()) for x in input("enter list:").strip()[1:-1].split(",")]
enter list:[2,4,5]
>>> input_list
[2, 4, 5]
>>> type(input_list)
<class 'list'>
>>>
Get a list of number as input from the user.
This can be done by using list in python.
L=list(map(int,input(),split()))
Here L indicates list, map is used to map input with the position, int specifies the datatype of the user input which is in integer datatype, and split() is used to split the number based on space.
.
You just need to typeraw_input().split()
and the default split() is that values are split by a whitespace.
a=[]
b=int(input())
for i in range(b):
c=int(input())
a.append(c)
The above code snippets is easy method to get values from the user.
Try this:
numbers = raw_input()
numberlist = list(numbers)
Answer is trivial. try this.
x=input()
Suppose that [1,3,5,'aA','8as']
are given as the inputs
print len(x)
this gives an answer of 5
print x[3]
this gives 'aA'