0

my intention is to execute an input N number of times by using a for loop. However, the code I wrote doesn't behave the way I expect it to.

Here I share my code:

N, K = map(int, input().split())

values ​​= (list(map(int, input().split()))[1:] for _ in range(N))
print(values)

When I execute the code the program ends without executing the inputs. Also, when I try to print the output, I get the following output:

<generator object <genexpr> at 0x000001D040ED03C0>

Here is a sample of how the program should work:

SampleInput

3 1000
2 5 4
3 7 8 9
5 5 7 8 9 10

in this case, N would be equal to 3, therefore 3 inputs should be executed

6
  • If your intention is to use a for loop, shouldn't there be a for loop somewhere in your code? Commented Aug 2, 2022 at 4:33
  • values ​​= [list(map(int, input().split()))[1:] for _ in range(N)], using ( ...) create generator expresion Commented Aug 2, 2022 at 4:34
  • Can you please provide an example of what you expect out of the program? Like, give us a sample of the user input and then what you expect the output to look like. Commented Aug 2, 2022 at 4:36
  • If you want values as a list, instead of generator expression use list comprehension Commented Aug 2, 2022 at 4:36
  • do you really want to enter multiple numbers N times or just one number N times? Do you need the split in the second line? It may be clearer if you show your expected output for a given set of inputs. Commented Aug 2, 2022 at 5:57

1 Answer 1

1

Just fix your code like this

values ​​= [list(map(int, input().split()))[1:] for _ in range(N)]

Instead of list comprehension, you can for in values like this

for i in values:
    print(i)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.