``` # Strategy 1 # plain_text = "the ships...." for c in plain_text: if c == ' ': ??? else: ??? #Strategy 2 #coded_text = "17,8,16_12,24,,14...." for coded_word in coded_text.split("_"): for coded_letter in coded_word.split(","): ....int(coded_letter)..... add (26-key) %26 ... find letter in this position ```
In [1]:
xs = [10,20,30]
xs.append(40)
xs
Out[1]:
[10, 20, 30, 40]

Python Dictionary

a set of name-value or key-value pairs
In [2]:
phones = { "John" : ["111-1234","111-1235"], "Alice": ["333-3333"] }
addresses = { "John" : "123 main street", "Alice": "101 elm street" }
print(phones)
print(addresses)
{'John': ['111-1234', '111-1235'], 'Alice': ['333-3333']}
{'John': '123 main street', 'Alice': '101 elm street'}
In [3]:
contacts = {
            "John" : {"phone":["111-1234","111-1235"],"address": "123 main street"},
            "Alice": {"phone":["333-3333"],"address": "101 elm street"} 
           }
print(contacts)
{'John': {'phone': ['111-1234', '111-1235'], 'address': '123 main street'}, 'Alice': {'phone': ['333-3333'], 'address': '101 elm street'}}
In [4]:
contacts["John"]["phone"][0][0]
Out[4]:
'1'

def find_person_give_phone(contacts,pno): ???

In [5]:
phones["David"] = ["222-2221","222-2222","222-2223"]
In [6]:
print(phones)
{'John': ['111-1234', '111-1235'], 'Alice': ['333-3333'], 'David': ['222-2221', '222-2222', '222-2223']}
In [7]:
contacts["Alice"]["phone"] = contacts["Alice"]["phone"] + ["333-3334"]
In [8]:
print(contacts)
{'John': {'phone': ['111-1234', '111-1235'], 'address': '123 main street'}, 'Alice': {'phone': ['333-3333', '333-3334'], 'address': '101 elm street'}}
In [11]:
import sys

def get_counts(fname):
# this function takes the name of a file as input parameter, fname
# it then reads the file into a string variable
# then proceeds to process the string for the count of letters
# answer should be returned in a dictionary object

    with open(fname,'r') as f:
        data = f.read().lower()

    d = {}
    for c in data:
        if c in "abcdefghijklmnopqrstuvwxyz":
            if c in d:
                d[c] = d[c] + 1
            else:
                d[c] = 1
    return d

def main():
    #counts = get_counts(sys.argv[1])
    counts = get_counts("ra.txt")
    print(counts)
    for c in counts:
        print(c," : ",counts[c])

main()
{'a': 158, 'l': 85, 'i': 158, 's': 136, 'w': 39, 'e': 246, 'n': 153, 'd': 55, 'v': 21, 'r': 99, 'y': 74, 't': 153, 'h': 91, 'g': 51, 'u': 67, 'f': 52, 'o': 175, 'm': 33, 'k': 11, 'b': 25, 'p': 27, 'c': 55, 'x': 5, 'q': 1, 'z': 2, 'j': 1}
a  :  158
l  :  85
i  :  158
s  :  136
w  :  39
e  :  246
n  :  153
d  :  55
v  :  21
r  :  99
y  :  74
t  :  153
h  :  91
g  :  51
u  :  67
f  :  52
o  :  175
m  :  33
k  :  11
b  :  25
p  :  27
c  :  55
x  :  5
q  :  1
z  :  2
j  :  1