D
D
Dozen Frozenballs2015-11-27 02:51:23
Python
Dozen Frozenballs, 2015-11-27 02:51:23

How to parse a simple set of words line by line into a list?

There is a dictionary in the form of a simple list of words in a text document. It is necessary to make a list from this set of words.
Example:
Yes:
names.txt

Андрей
Евгений
Иван
Сергей

Necessary:
names = [Андрей, Евгений, Иван, Сергей]

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander, 2015-11-27
@Rossihin

f = open('data.txt', 'r')
names = f.readlines()
f.close()

A
Alexander Taratin, 2015-11-27
@Taraflex

https://stackoverflow.com/questions/3277503/python...

D
Dozen Frozenballs, 2015-11-27
@Rossihin

I found a crooked way.
one)

names = ['''
Андрей
Евгений
Иван
Сергей
''']

print (names)

The interpreter returned :
2) I copied the interpreter data and wrote the following code:
a = "Андрей\nЕвгений\nИван\nСергей\n"
print(a)
print (a.splitlines())

At the output, the interpreter gave me what I needed
['Andrei', 'Eugene', 'Ivan', 'Sergey']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question