Posts in 2021
-
10-13 Stringy
Wednesday, October 13, 2021 in Daily
Stringy Storage of a Graph The (until now fictional) “string method” of storing a graph lists strings of connected vertices on every line. Assignment: Write a function that accepts an already open file (returned from open) and creates an …
-
10-13 Basics
Wednesday, October 13, 2021 in Daily
Python proficiency questions. Suppose x is an object of class CC. What method is run by str(x)? Give an efficient way to remove the trailing newlines from an array of strings read from a file. ['the\n','mouse\n','went\n','up\n','the\n','clock\n'] …
-
10-08 Shortest
Thursday, October 07, 2021 in Daily
Skills base Sorting into a new container: ys = sorted(..., reverse=True) Sorting by mutation, changing the existing container: xs.sort(reverse=True) Field width: f"{x:10}" puts x in a space 10 characters wide. Improvements to graph.py …
-
10-06 Graph
Wednesday, October 06, 2021 in Daily
Default Dictionary Sometimes you want to have a “default value” in a dictionary. The default value is returned whenever you ask for the value of a key that is not in the dictionary. A typical use would be counting words, where the count …
-
09-21
Friday, September 17, 2021 in Daily
Reading You need to convert strings to numbers with the int function. Read a single number: int(input()) Read a list of numbers: [int(n) for n in input().split()] If different items in the list have different meanings, it can be useful to give them …