Professional Documents
Culture Documents
Programming Assignment Unit 7
Programming Assignment Unit 7
alphabet = "abcdefghijklmnopqrstuvwxyz"
test_dups = ["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"]
test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy dog"]
# Downey, A. (2015). Think Python: How to think like a computer scientist. Needham,
Massachusetts: Green Tree Press.
def histogram(s):
d = dict()
for c in s:
if c not in d:
d[c] = 1
else:
d[c] += 1
return d
#Part 1
def has_duplicates(s):
h=histogram(s)
if v > 1:
return True
return False
for s in test_dups:
if has_duplicates(s):
print(s,"has duplicates")
else:
print(s,"has no duplicates")
#Part 2
alphabet = "abcdefghijklmnopqrstuvwxyz"
test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy dog"]
# Downey, A. (2015). Think Python: How to think like a computer scientist. Needham,
Massachusetts: Green Tree Press.
def histogram(s):
d = dict()
for c in s:
if c not in d:
d[c] = 1
else:
d[c] += 1
return d
def missing_letters(st_2):
missings = [] #Empty list
dic_2 = histogram(st_2)
for missing in alphabet:
if missing not in dic_2:
missings.append(missing)
missings.sort()
return "".join(missings)
for miss_let in test_miss:
st_3 = missing_letters(miss_let.replace(" ",""))
if st_3 != "":
print(miss_let, "is missing letters", st_3)
else:
print(miss_let,"uses all the letters")
Output Part 1
Output Part 2