#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Felix Muzny 10/14/2022 DS 2000 Lecture 11 - iteration with lists of lists, lists and mutability (the final chapter of scope), functions and optional parameters, functions and functions as parameters Logistics: - Homework 5 is due *next* Friday 10/21 @ 9pm - 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 - lists of lists & slicing --- """ """ Warm-up 2 - lists of lists and loops --- """ """ """ """ Academic Integrity --- This is not a fun topic, help me avoid having to address it any further. Homeworks: - done individually You all are beginning programmers. I know very well that it can often *feel* like there is only one correct solution to a problem. In reality, we expect to see a great deal of variation in programs that are submitted (variation beyond "surface level" traits like variable names) When we see two programs that are the same, this is equivalent to seeing two essays submitted in an English course that are word-for-word copies of one another. Check in with your DS 2001 section for policies about collaboration. """ """ List function — convert to ints --- Write a function, convert_int, that takes a list as a parameter and returns a new list with all the values in the original list converted to an integer. Assume that all values in the original list can be converted to ints. """ """ Lists and mutability (scope: the final chapter!) --- So far: when we've passed parameters into functions, we've passed *copies* of their *values*. Example: """ # def increment(x): # x = x + 1 # print("int in increment", x) # def main(): # x = 7 # increment(x) # print("int in main", x) # # now, we'll explore lists # main() """ Vocab --- pass-by-value: pass-by-reference: """ """ List functions - pure vs. mutator --- There are two kinds of list functions: pure: sorted_ls = sorted(ls) mutator: ls.sort() """ """ Optional parameters --- examples with python built-in functions (you've already used these a lot with matplotlib!) """ import matplotlib.pyplot as plt # xs = list(range(0, 10)) # ys = [1, 5, 6, 4, 2, -4, 3, 2, 5, 10] # plt.plot(xs, ys, ".") # plt.show() """ Writing our own function with an optional parameter: write a function, generate_list, that generates a list of 10 random integers. Use optional parameters to define the lower and upper range of integers to be generated. """ import random """ Passing functions as parameters --- Using our function that we wrote from before (convert_int), write a new version that will convert everything from a list into a string. """ # if we have time """ if __name__ == "__main__": --- Writing our very own modules! """ """ Next time: - dictionaries """