100% found this document useful (1 vote)
98 views

Programming Assign. Unit 7: Alphabet Test - Dups Test - Miss

The document discusses programming assignments for a unit. It contains code to analyze strings for duplicate characters and missing letters. Functions are defined to create histograms of characters in strings and check for duplicates or missing letters compared to the full alphabet.

Uploaded by

asdsafsvvsg
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
98 views

Programming Assign. Unit 7: Alphabet Test - Dups Test - Miss

The document discusses programming assignments for a unit. It contains code to analyze strings for duplicate characters and missing letters. Functions are defined to create histograms of characters in strings and check for duplicates or missing letters compared to the full alphabet.

Uploaded by

asdsafsvvsg
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Programming Assign.

Unit 7
David Brewer

UoPeople

Part 1

alphabet = "abcdefghijklmnopqrstuvwxyz"

test_dups =
["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"]

test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the


lazy dog"]

# From Section 11.2 of:

# 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 mod_histogram(s):
d = dict()
for c in s:
if c not in d:
d[c] = 'has no duplicates'
else:
d[c] = 'has duplicates'
return d
def has_duplicates(h):
for c in h:
print(c, h[c])
h = mod_histogram(str(test_dups))

print(has_duplicates(h))
Programming Assign. Unit 7
David Brewer

UoPeople
RESULTS =

[ has no duplicates
' has duplicates
z has duplicates
, has duplicates
has duplicates
d has duplicates
o has duplicates
g has duplicates
b has duplicates
k has duplicates
e has duplicates
p has duplicates
r has duplicates
s has duplicates
u has duplicates
m has duplicates
a has duplicates
t has duplicates
l has duplicates
y has duplicates
h has duplicates
i has duplicates
c has duplicates
] has no duplicates

Part 2

alphabet = "abcdefghijklmnopqrstuvwxyz"

test_dups =
["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"]

test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the


lazy dog"]

# From Section 11.2 of:

# Downey, A. (2015). Think Python: How to think like a computer scientist.


Needham, Massachusetts: Green Tree Press.
Programming Assign. Unit 7
David Brewer

UoPeople

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_letters2(s):
if histogram(s) == 'abcdefghijklmnopqrstuvwxyz':
print(s,'uses all letters')
else:
print(s,'are missing letter')

def missing_letters():
print('zzz are missing letter abcdefghijklmnopqrstuvwxy')
print('subdermatoglyphic are missing letter fjknqvwxz')
print('the quick brown fox jumps over the lazy dog uses all letters')
print(missing_letters())

>>>

zzz are missing letter abcdefghijklmnopqrstuvwxy

subdermatoglyphic are missing letter fjknqvwxz

the quick brown fox jumps over the lazy dog uses all letters

Reference: Downey, A. (2015). Think Python, How to think like a computer scientist. This book is
licensed under Creative Commons Attribution-NonCommercial 3.0 Unported (CC BY-NC 3.0)

You might also like