A
A
Alexander Semenenko2018-02-20 17:15:27
Python
Alexander Semenenko, 2018-02-20 17:15:27

How to extract a line and a word from a file in python?

Let's say there is a file, it has several lines, each line has the same number of words. For example 5 lines, each line has 4 words. How can you, for example, deduce the 4th word from the 2nd line?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2018-02-20
@semenenko88

data = """ Как на питоне вытащить из файла...?
Допустим есть файл, в нем несколько строк,..."""

for s in data.splitlines():
    print(s.split()[2])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question