Lec10ListsDicts

# Lec10ListsDicts - Lecture 9 Lists In Class Today: 1) Three...

This preview shows pages 1–2. Sign up to view the full content.

Lecture 9 – Lists – In Class Today: 1) Three solutions to Friday’s encryption lab 2) Memory, what it looks like, how lists are different 3) Bunch of examples using lists def encrypt(string): cipherText = “” for ch in string: letter =encryptLetter(ch) cipherText = cipherText + letter return cipherText # solution #1 def encryptLetter(letter): number = (ord(letter)-ord(‘a’) + 13)% 26 return chr(number + ord(‘a’)) # solution #2 def encryptLetter(letter): number = ord(letter) if (letter < ‘n’): newNumber = number+13 else: newNumber = number-13 return chr(newNumber) # solution #3 def encryptLetter(letter): key = “nopqrstuvwxyzabcdefghijklm” number = ord(letter) – ord(‘a’) return key[number] What does memory look like? Remember how to draw memory like on the board a=b -> a and b are pointing to the SAME memory a = b*2 -> makes a new list for a a = b+c -> also makes a new list for a a[0] 4 a[x] a[1] 7 a[0] + x 4 + 1 5 a[x] + 0 a[1]+0 -> 7 + 0 -> 7 Relationship between lists and loops

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 12/27/2011 for the course CMPSC 8 taught by Professor Franklin during the Fall '09 term at UCSB.

### Page1 / 3

Lec10ListsDicts - Lecture 9 Lists In Class Today: 1) Three...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online