
# Oct 18, 2017
# longestName has two inputs, a list of names (one word each)
# and a letter. It returns the longest name that starts 
# with that letter. Assume all names start with a 
# capital letter and letter is a capital letter
def longestName(alist, letter):
    longest = ''
    for name in alist:
        if letter == name[0] and len(name) > len(longest):
            longest = name
    return longest 






# positionLongestName has the same two inputs. This
# returns the index position of the longest name
# that starts with letter
def positionLongestName(alist, letter):
    pos = 0
    for index in range(len(alist)):
        name = alist[index]
        longest = alist[pos]
        if letter == name[0] and len(name) > len(longest):
            pos = index        
    return pos

#another version with enumerate
def positionLongestName2(alist, letter):
    pos = 0
    for (index,name) in enumerate(alist):
        longest = alist[pos]
        if letter == name[0] and len(name) > len(longest):
            pos = index        
    return pos


    
names = ['Fred', 'John', 'Sue', 'Joe', 'Mo', 'Sabrina', 'Mary', 'Sarah', 'Jackson']
print longestName(names,'J')
print positionLongestName(names, 'J')
print positionLongestName2(names, 'J')
print longestName(names,'S')
print positionLongestName(names, 'S')
print positionLongestName2(names, 'S')

