Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a list of strings when input is not separated python

I have this name list that i got online,the list is 200 names long,here is a sample of it that i have saved in a text file.

John
Noah
William
James
Logan
Benjamin
...

I want them to be a list of strings i.e

x=['John','Noah','William',...]

I searched for questions similar but didn't find exactly what i need, any help is much appreciated.

like image 637
wishmaster Avatar asked Mar 13 '26 04:03

wishmaster


1 Answers

If the input is a file you can do...

x = []
with open('file_name', 'r') as f:
    for line in f:
       x.append(line.strip())
like image 92
The Pineapple Avatar answered Mar 14 '26 16:03

The Pineapple



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!