-1

How to take multiple input in a single line for tuple and list ?

a= list(x = int(input()) for x in range(n)  if x > 0)

''' it has an error , how can I solve it and use similar code for tuple '''

1 Answers1

0

You can use filter on your comprehension, like this:

a = list(filter(lambda x: x>0, (int(input()) for _ in range(n))))

For n = 5 and the input:

1
0
3
-10
4

it would print:

[1, 3, 4]
Adam.Er8
  • 12,675
  • 3
  • 26
  • 38