Shivansh Singh
Shivansh Singh

Reputation: 559

First line integer n as input, next line n number as input separated by space

1.First line an integer N as input

2.second line N numbers of integer as input separated by space

Example 1

4

11 22 44 12

Example 2

3

1 9 11

Tried this

l=[map(int,input().split()) for i in range(n)]

Taking input in separate line

Actual Output

[map,map,map,map]

Excepted output

[11,22,44,12]

Upvotes: 0

Views: 4573

Answers (1)

wpercy
wpercy

Reputation: 10090

Don't worry about taking n first, you can just take an input string and split on spaces like this

l = [int(i) for i in input().split(" ")]

then n is the length of that list

n = len(l)

If you do want to take n first, to make sure you only take a certain length list, you can do something like

n = int(input())
l_input = input()
l = [int(i) for i in l_input.split(" ")]

assert len(l) == n, "list is not of correct length"

Upvotes: 1

Related Questions