Jed Rembold
November 13, 2024
Let’s consider a greatly simplified Enigma machine, which only has
one rotor that is not turning. So the signal goes through the rotor then
the reflector and back through the rotor. Given the rotor and reflector
mappings shown to the right, what would the word
python
encrypt to?
aicmnz
hnktge
rfqbls
zghpmy
digits = { 0, 1, 2, 3, 4, 6, 7, 8, 9 }
squares = { 0, 1, 4, 9 }
primary = { "red", "green", "blue" }
{ }
!
set()
.3 in primes
A.union(B)
A | B
A.intersection(B)
A & B
A.difference(B)
A - B
A.symmetric_difference(B)
A ^ B
If we have the following sets from earlier:
digits = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } |
evens = { 0, 2, 4, 6, 8 } |
odds = { 1, 3, 5, 7, 9 } |
primes = { 2, 3, 5, 7 } |
squares = { 0, 1, 4, 9 } |
What is the value of each of the following:
Looking at the same sets:
digits = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } |
evens = { 0, 2, 4, 6, 8 } |
odds = { 1, 3, 5, 7, 9 } |
primes = { 2, 3, 5, 7 } |
squares = { 0, 1, 4, 9 } |
What is the set resulting from: \[ (\text{primes} \cap \text{evens}) \cup (\text{odds}\cap\text{squares})\]
A == B
A <= B
A < B
{ x for x in range(0,100,2) }
Function | Description |
---|---|
len(|||set|||) |
Returns the number of elements in a set |
|||elem||| in |||set||| |
Returns True if
|||elem||| is in the set |
|||set|||.copy() |
Creates and returns a shallow copy of the set |
|||set|||.add(|||elem|||) |
Adds the specified |||elem||| to the
set |
|||set|||.remove(|||elem|||) |
Removes the element from the set, raising a
ValueError if it is missing |
|||set|||.discard(|||elem|||) |
Removes the element from the set, doing nothing if it is missing |
Name | Class | Q1 | Mid | Q3 | Final |
---|---|---|---|---|---|
Sally | Python | A | B | B | A |
Jake | Python | B | B | B | C |
James | Astro | B | B | A | |
Lily | Astro | A | A | B | |
Ben | Python | C | B | B | A |
{
"Python": {
"Sally": ["A", "B", "B", "A"],
"Jake": ["B", "B", "B", "C"],
"Ben": ["C", "B", "B", "A"]
},
"Astro": {
"James": ["B", "B", "A"],
"Lily": ["A", "A", "B"]
}
}
json
json.load(|||file_handle|||)
json.dump(|||data_object|||, |||file_handle|||)
with open(|||filename|||) as |||fhandle|||:
syntaxTo read a JSON file into a variable
data
:
import json
with open('file.json') as fh:
data = json.load(fh)
To write a variable with complex structure out to a JSON file:
import json
with open('file.json', 'w') as fh:
json.dump(data, fh)
[1, 2, 3,]
is perfectly
fine in Python, but illegal in JSON