Jed Rembold
April 26, 2021
Three of the below expressions are valid; one is not. Which one would return an error?
{'A': {'B': (1,2)}, 'C': 3}{1, 2, (3,4), 5 }[{'Alpha': 1, 'Omega': 26}, {2, 3, 4, 5}]{['A', 'B']: {1, 2}}For answer Gandalf cried aloud to his horse. “On Shadowfax! We must hasten. Time is short. See! The beacons of Gondor are alight, calling for aid. War is kindled. See, there is the fire on Amon Dìn, and flame on Eilach; and there they go speeding west: Nardol, Erelas, Min-Rimmon, Calenhad, and the Halifirien on the borders of Rohan.”
– J.R.R. Tolkien, The Return of the King, 1955
None
None value is commonly shown as just a diagonal line across the boxclass SignalTower:
def __init__(self, name, link=None):
self.name = name
self.link = link
def __str__(self):
s = self.name
if self.link is not None:
return f"{s} -> {str(self.link)}"
return s
def get_name(self):
return self.name
def signal(self):
print(f"Lighting {self.name}!")
if self.link is not None:
self.link.signal()
@staticmethod
def create_chain(names):
towers = None
for name in reversed(names):
towers = SignalTower(name, towers)
return towers
if __name__ == '__main__':
names = [
'Minas Tirith', 'Amon Din', 'Eilenach', 'Nardol',
'Erelas', 'Min-Rimmon', 'Calenhad', 'Halifierien',
'Rohan'
]
towers = SignalTower.create_chain(names)
print(towers)
towers.signal()
“our repeated petitions have been answered by repeated injury.”
Storing text as one long string is cumbersome when insertions need to be made
Alternatively, could store the text as a linked list of words
Allows you to insert new words without changing any other words in memory!