Enter a string in the Python list

Asked 2 years ago, Updated 2 years ago, 91 views

When the number of inputs of the string and the maximum number of files to be input in the first code is 20,000

num = int(input())
stra = [0]*20000

Define it like this.

for i in range(0,num,1) :
    stra[i] = input()
stra.sort()

When I sort the input strings, I get an error because the string '<' not supported between instances of 'int' and 'str' is the same number. How do I declare a list?

string python input

2022-09-21 20:05

1 Answers

In Python, the list can be used dynamically.

You don't need an initialization like an array.

Do it as below.

num = int(input())
stra = []
for i in range(0,num,1) :
    stra.append(input())
stra.sort()


2022-09-21 20:05

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.