I have a text file ("name_data.txt"
) that has the following contents:
name: Kelo
family name: Lam
location: Asia
members: Kelo, Kiko, Jil
name: Miko
family name: Naiton
location: Japan
members: Miko,Kayati
The text file keeps going with the same pattern (name, family name, location, members)
I want to print out the first line and then print every 5th line so I would be printing only the line with "name" in the beginning. I then want to have a list of the names
I want my output to be :
["Kelo","Miko"]
So far, I have gotten (although, it is wrong):
name_data= load_local_file('name_data.txt',ignore_header=False,delimiter='\t')
def __init __(name_reader):
names=list()
count=0
name_line=5
line_number=0
for name in name_data:
if line_number<5:
line_number +=1
if line_number ==5:
names.append(line_number)
Assuming that
name_data
is a list of lines in the file, you can do