Solution Exercise 27

Write a program that maps a list of words into a list of integers representing the lengths of the correponding words.

def map_strings_to_lengths(list_of_words):
    len_list = []
    for s in list_of_words:
        len_list.append(len(s))
    return len_list

def main():
    list_of_words = ["hi", "Paris", "Hamster", "New England"]
    length_list = map_strings_to_lengths(list_of_words)
    print(length_list)
    
    #This very same thing can be done with a list comprehension
    length_list = [len(s) for s in list_of_words]
    print(length_list)
    
if __name__ == '__main__':
    main()