#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Felix Muzny 9/30/2022 DS 2000 Lecture 7 - for loops, lists, constants Logistics: - Homework 3 is due tonight @ 9pm -> this homework is hard -> I am planning on ending lecture 10 minutes early to answer HW 3 questions. Please do your best to focus on today's material until then! - Homework 4 is now available on the course website -> this homework is designed to be shorter than HW 3 -> it does incorporate concepts from this lecture though - Quiz 4 will be available on Monday - remote attendance (https://bit.ly/remote-ds2000-muzny) Three ways to participate (please do one of these!) 1) via the PollEverywhere website: https://pollev.com/muzny 2) via text: text "muzny" to the number 22333 to join the session 3) via Poll Everywhere app (available for iOS or Android) Warm-up 1 - while loops + accumulator --- Warm-up 2 - nested while loops --- """ """ Lists: what we rememember --- """ """ Getting a list from a string: str.split() ----- Say I have a string, for instance, the first words of Middlemarch by George Eliot: """ print("split examples") fancy_text = "Who that cares much to know the history of man" # If I want a list from this string, I use the str.split() function: words = fancy_text.split() print(words) # I could also split on the letter "a" to demonstrate what python # is doing—it is using the "splitter" string as the thing to delete # and separate the original string into smaller substrings. by_as = fancy_text.split("a") print(by_as) # We'll start from here on Friday! """ A new kind of loop: for loops --- Syntax: """ """ for loops + files --- """ """ for loops + files + str.split() --- """ """ Example problem --- Write a program, analyze_dist.py, that reads the data from the file muzny_distances.txt and graphs it accordingly on a scatter plot. """ """ More graph types: bar chart ----- """ """ Example problem, updated x 1 --- Update the program to display the information on a bar chart instead. """ """ Plotting multiple points at the same time ----- """ """ Example problem, updated x 2 --- Update the program to plot all points simultaneously. """ """ Example problem, updated x 3 --- Update the program to plot the strange_distances.txt in a separate series. Add a legend. """ """ Lists + indexing + loops --- """ """ for i in range(num) --- """ # example problem looping over a list w/ indexes """ strings & indexing --- """ # example problem looping over a string w/ indexes """ Next time: - functions!!! """