""" Felix Muzny DS 2000 Lecture 7 September 27, 2024 A program to visualize the top 10 salaries in MA 2023 (from a csv file, using lists!) """ # using the .csv! FILENAME = "ma_salarytop10.csv" def main(): print("lec 7 - ma salaries with a csv") # step 1 - gather data with open(FILENAME, "r") as salary_file: # read one line line = salary_file.readline() # make line into list salaries = line.split(",") # take a look at the list print(salaries) # look at the first salary print(salaries[0]) print() # print out all the salaries print("all salaries") for num in salaries: print(num) # oh no! we have to make the list contents into ints first # must use for i in range so that we have index # information for i in range(len(salaries)): salaries[i] = int(salaries[i]) # if a salary is above 9000000 # add to a high salaries list # 1) initialize list outside high_salaries = [] for num in salaries: if num > 9000000: # 2) add to list inside loop high_salaries.append(num) print("high salaries:", high_salaries) main()