Reputation: 17
n=int(input())
arr=[input().split(",")]
e=len(arr)
print(e)
the input I gave is n=3 and arr=1,0,2 and its output is 1 why does it print the length of list as 1 instead 3 since it has 3 elements. if it is wrong way to use what should I use in its place
Upvotes: 1
Views: 37
Reputation: 169
input().split(",")
statement returns a list. By using [input().split(",")]
you are adding retuned list into another list making it a 2D list. According to your code arr = [[1,0,2]]
. You are getting the length of this 2D list which is 1.
Upvotes: 0
Reputation: 260580
You are wrapping [input().split(",")]
in a list, so there is only one element (arr will be a list containing a single list).
Use instead: arr=input().split(",")
Upvotes: 1