Bit about Bytes: Understanding Python Bytecode See James BennettWriting more efficient Python code.
I hereby solicit suggestions for the video of the day. Please email me your ideas with explanations. Selected entries will win 5 homework points. If your video is played at the beginning of class, you must also briefly explain something about the video and something about yourself — in person.
x = [True, True, False] any(x) and not all(x)What is the output of the above code?
https://pollev.com/slade You may also download the app to your phone. Use the "slade" poll id.
Ignore Previous Instructions: Attacks on AI Systems and What to Do About It. Monday, October 28, 2024 | 4:00pm Horchow Hall, GM Room (55 Hillhouse Avenue)The Schmidt Program on Artificial Intelligence, Emerging Technologies, and National Power will host a talk by Ram Shankar Siva Kumar, founder and head of the AI Red Team at Microsoft, which proactively attacks AI systems to identify vulnerabilities. He will provide an overview of the art and science of attacking AI systems and its societal implications.
Kumar is a leading expert in the intersection of machine learning and security. He is the co-author of the 2023 book, "Not with a Bug, But with a Sticker," and is currently a tech policy fellow at UC Berkeley and an affiliate at Harvard’s Berkman Klein Center. The event is open to the Yale community; registration is required.
hw4: staff solution for myhash had errors:
def __eq__(self, other): if type(other) != type(self): return False if self.table == other.table: return True else: return FalseThe eq method compares lists, in which order matters. However, for the hash table buckets, the order does not matter.
>>> from hw4a import * >>> h = myhash(5) >>> h.put('a',1) >>> h.put('f',2) >>> h2 = myhash(5) >>> h2.put('f',2) >>> h2.put('a',1) >>> str(h) "myhash([[('a', 1), ('f', 2)], [], [], [], []])" >>> str(h2) "myhash([[('f', 2), ('a', 1)], [], [], [], []])" >>> h == h2 False >>>You might want to use flatten as a set comprehsion, so that order does not matter.
I have fixed the problem in hw4a.pyc. Note that the tables do not need to be the same size.
>>> from hw4a import * >>> h = myhash() >>> h.put('a',1) >>> h.put('b',2) >>> h2 = myhash(5) >>> h2.put('b',2) >>> h2.put('a',1) >>> str(h) "myhash([[], [], [], [], [], [], [], [], [], [], [('a', 1)], [('b', 2)], [], [], [], [], [], [], [], []])" >>> str(h2) "myhash([[('a', 1)], [('b', 2)], [], [], []])" >>> h == h2 True
There is a different problem with the copy method.
def copy(self): h = myhash(self.size) h.table = self.table[:] h.count = self.count return hThis code makes a shallow copy of the list. We need to make a deep copy of the embedded lists. Otherwise, there are problems.
from hw4a import * >>> h = myhash(5) >>> h.put('a', 1) >>> h2 = h.copy() >>> str(h) "myhash([[('a', 1)], [], [], [], []])" >>> str(h2) "myhash([[('a', 1)], [], [], [], []])" >>> h.put('b',2) >>> str(h) "myhash([[('a', 1)], [('b', 2)], [], [], []])" >>> str(h2) "myhash([[('a', 1)], [('b', 2)], [], [], []])"The current staff solution, hw4a.pyc, fixes these issues. The previous version is hw4abad.pyc.
There will be a UNIX question, as in the first midterm. Here is a sample UNIX transcript (solutions) UNIX will cover through principle 3.
The version of Python on the zoo is 3.10. That is the version used by this assignment and the autograder. There were some major changes to byte codes in version 3.11, and for that matter, in version 3.9. See dis.html and specify version 3.10.