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()

Just little errors, first need to use raw_input() when inputting strings, and have to use a different variable instead of search in the for loop.

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 = raw_input('Enter search name: ')
    for nameSearch in list_of_names:
        if search == nameSearch:
            print search

def print_names(list_of_names):
    for name in list_of_names:
        print name
        
if __name__ == '__main__': main()
Comments
very helpful
This article has been dead for over six months. Start a new discussion instead.