''' Honors Series - Data Science Fall 2020 List Examples ''' def main(): # Example 1 -- Create a list and print each element one at a time lst = ['a', 'b', 'c', 'd', 'e', 'f'] for item in lst: print(item) # Example 2 -- Create a list and add together two of its values lst = [2.5, 4.87, 6.0, 8.2] num = lst[0] + lst[1] print(num) # Example 3 -- Create a list, and sum together all its values lst = [1, 4, 9, 16, 25] total = sum(lst) print('Total of everything in the list is:', total) # Example 4 -- Create an empty list, and add elements to it one at a time lst = [] for i in range(5): num = float(input('Enter a number.\n')) lst.append(num) print('Your list is', lst) # Example 5 -- Create a nested list and print ONE value at a time nested = [['a', 12, 1980], ['b', 13, 1981]] print('Nested[0][0]...', nested[0][0]) print('Nested[0][1]...', nested[0][1]) print('Nested[1][2]...', nested[1][2]) # Example 6 -- Create a nested list and turn one column into # a list of its own nested = [['a', 12, 1980], ['b', 13, 1981]] years = [] for row in nested: years.append(row[2]) print(years) main()