I have a text file which consists of names of different countries as follows:
I have to extract all these names and store them inside a list using python.
Python Code:
with open('a.txt') as x:
b = [word for line in x for word in line.split()]
print(b)
Problem: The above python codes works absolutely fine but the only problem is that if it finds any space between any 2 words, it is storing them as two separate words in a list. Whereas, I want to retrieve the names line by line and store that entire word as a single word.
For Example: I want to store the word Antigua & Deps as a single word inside the list. Whereas, it is storing it as 3 different words.
Can anyone please help me out with this problem?