Automatically generate Python lists

Asked 2 years ago, Updated 2 years ago, 45 views

How can I make a code that makes a list of n when I get the number n from the user? I was going to write a for statement, but it's hard...

python list

2022-09-22 17:55

1 Answers

Like this? Actually, I don't understand the question because it has no purpose.

In [8]: L = [[] for _ in range(int(input("Input a number: ")))]                 
Input a number: 5

In [9]: L                                                                       
Out[9]: [[], [], [], [], []]


2022-09-22 17:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.