this should do it:
with open("malenames.txt") as f:
for line in f:
print (line.split()[0])
Question
I can't get it to print only the names.
This is what I got so far
and here is the link for the malenames.txt:
http://www.ics.uci.edu/~kay/malenames.txt
from collections import namedtuple
FN = namedtuple('FN','name percent people rank')
FirstN = namedtuple('FirstN','FN')
def firstname()->str:
'''returns a firstname from text file'''
filein = open('malenames.txt','r')
for str in filein:
s = str.split('\t')
print (s)
FN1 = FN(s)
F1 = FirstN(FN1)
for name in F1:
print(name)
firstname()
La solution
this should do it:
with open("malenames.txt") as f:
for line in f:
print (line.split()[0])