hey guyz,
i need to make a code for searching the names in the list txt. i pretty much got the other parts, but when im kinda stuck on searching.
def main():
list_of_names = open_file()
print"""
--------------- non sorted---------------------"""
print_names(list_of_names)
print """
----------------sorted-------------------------"""
list_of_names = sort_names(list_of_names)
save_file(list_of_names)
search_names(list_of_names)
def open_file():
list_of_names = []
name = open('names.txt','r')
s_names = name.readline()
while s_names != '':
s_names = s_names.rstrip('\n')
list_of_names.append(s_names)
s_names = name.readline()
return list_of_names
def sort_names(list_of_names):
list_of_names.sort()
print_names(list_of_names)
return list_of_names
def save_file(list_of_names):
Name = open('namestwo.txt','w')
for name in list_of_names:
Name.write(name + '\n')
def search_names(list_of_names):
search = input('Enter search name: ')
for search in list_of_names:
print search
def print_names(list_of_names):
for name in list_of_names:
print name
main()