Sequences
Question 0
Fill out what python would display at each step if applicable.
Note: (keep in mind list slicing creates a brand new list, does not modify existing list)
i.
Let’s imagine you order a mushroom and cheese pizza from La Val’s, and that they represent your order as a list:
1 | >>> pizza = ['cheese', mushrooms'] |
A couple minutes later, you realize that you really want onions on the pizza. Based on what we know so far, La Val’s would have to build an entirely new list to add onions:
For each of the following lists, what is the list indexing expression that evaluates to 7? For example, if x = [7], then the answer would be x[0]. You can use the interpreter or Python Tutor to experiment with your answers.
1 | >>> x = [1, 3, [5, 7], 9] |
1 | def fib_iter(n): |
1 | # Rational arithmetic |
A list is an ordered collection, or sequence.
1 | interface List<E> { |