Compsci 06/101, Fall What's ahead in Compsci 6/101? l Software architecture and design, why Jotto has modules and how communication works We write small programs, want to understand some principles of larger programs Software design in the small and in the large: different! l Dictionaries: associating keys with values Arguably the most useful method for structuring data How does Google find 'good' sites for a query? How do we find what region in a genome encodes a protein? How do we determine literary/other fingerprints?
Compsci 06/101, Fall Jotto: The Program Architecture l You write jottoModel.py This is the guts, brains, state of the program Keeps track of how the game is progressing Functions in the module communicate via global state l We provide two views: command-line and GUI These all you to view and control the model Both view-controllers: jottoMain.py and jottoGui.py know about the model, but model doesn't know about them l Model-View or Model-View-Controller Often the model knows there is/are view(s) not Jotto
Compsci 06/101, Fall Maria Klawe Chair of Computer Science at UBC, Dean of Engineering at Princeton, President of Harvey Mudd College, ACM Fellow,… Klawe's personal interests include painting, long distance running, hiking, kayaking, juggling and playing electric guitar. She describes herself as "crazy about mathematics" and enjoys playing video games. "I personally believe that the most important thing we have to do today is use technology to address societal problems, especially in developing regions"
Compsci 06/101, Fall Useful Computer Science l a n+St,+Durham,+NC (Blue+Coffee+Express)&daddr=2324+Duk e +University+Road,+Durham,+NC+27708&hl=en&geocode=FcNJJQIdYw 5 M-yGT6vAZOfvdQg%3B&mra=ls&sll= , &sspn= , a n+St,+Durham,+NC (Blue+Coffee+Express)&daddr=2324+Duk e +University+Road,+Durham,+NC+27708&hl=en&geocode=FcNJJQIdYw 5 M-yGT6vAZOfvdQg%3B&mra=ls&sll= , &sspn= , Blue Coffee Express Durham 2324 Duke University Road
Compsci 06/101, Fall How does this work? l
Compsci 06/101, Fall What is a dictionary, map, hash, table? l Abstraction: collection of (key,value) pairs What kind of ice-cream do you like? You are the key, ice cream is the value Robert Susan Jeff Alex Bruce Sam
Compsci 06/101, Fall What does this code do? How? def fileStatsList(filename): file = open(filename) statList = [] for word in file.read().split(): found = False for pair in statList: if pair[0] == word: pair[1] += 1 found = True break if not found: statList.append([word,1]) file.close() return statList
Compsci 06/101, Fall Faster, Cheaper, Totally in Control def fileStatsDictionary(filename): file = open(filename) stats = {} for word in file.read().split(): if word in stats: stats[word] += 1 else: stats[word] = 1 file.close() return stats
Compsci 06/101, Fall Accessing map l Index a map by a key, using […] Like indexing a list, but index is a string, …. not integer! Works internally by associating a number with the key This association is known as hashing the key l Methods for dictionaries: .clear(),.get(key),.get(key,default) .keys(),.values(),.items() l When using iteration or x in d, we're talking keys Iterate over keys, query about keys, and so on
Compsci 06/101, Fall Literary Fingerprint l Timing and playing with code in fingerPrint.py How do we find out how fast this is? How do we change the format of the output? Can we organize output differently? l How can we find 'other' fingerprints Shazaam, genome, images What will be the key, what will be the value?