How to take input in list comprehension in python

Here is my code:

n = int(input())
p = []
for x in range(n+1):
    a,b,c,d = input().split()
    if x >= 1:
        p.append(int(b))

i try to use list comprehension ,but there’s something wrong in my code :frowning:
How can i fix this?

I have done so far:

p = [int(b) for x in range(n+1) if x >= 1 a,b,c,d = input().split()]

You don’t. List comprehensions are pure expressions that are not supposed to do I/O or do side effects. Use a regular loop instead.

1 Like

Thanks chuckadams :sparkling_heart:
is there any way to make my code more efficient ?

Not really, but it’s not inefficient in the first place.

1 Like