0% found this document useful (0 votes)
100 views2 pages

00

The document contains code to analyze strings for duplicate characters and missing letters. It defines functions to create a character histogram and check for duplicates. Test strings are analyzed and output whether they have duplicates or missing letters. The code is then expanded to find missing letters by comparing the string histogram to the alphabet. Test strings are run through this and output if they are missing letters or use all letters.

Uploaded by

rah h
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
100 views2 pages

00

The document contains code to analyze strings for duplicate characters and missing letters. It defines functions to create a character histogram and check for duplicates. Test strings are analyzed and output whether they have duplicates or missing letters. The code is then expanded to find missing letters by comparing the string histogram to the alphabet. Test strings are run through this and output if they are missing letters or use all letters.

Uploaded by

rah h
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Part 1

#Code
alphabet = "abcdefghijklmnopqrstuvwxyz"
test_dups = ["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"]
def histogram(s):
d = dict()
for c in s:
if c not in d:
d[c] = 1
else:
d[c] += 1
return d
def has_duplicates(s):
for val in histogram(s).values():
return True
return False
for str_1 in test_dups:
if has_duplicates(str_1):
print(str_1, "has duplicates")
else:
print(str_1, "has no duplicates")

Output:

zzz has duplicates


dog has no duplicates
bookkeeper has no duplicates
subdermatoglyphic has no duplicates
subdermatoglyphics has duplicates
>>>

Part 2
#Code

alphabet = "abcdefghijklmnopqrstuvwxyz"
test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy
dog"]
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(str_2):
missings = [] #Empty list
dict_2 = histogram(str_2)
for missing in alphabet:
if missing not in dict_2:
missings.append(missing)
missings.sort()
return "".join(missings)
for miss_let in test_miss:
str_3 = missing_letters(miss_let.replace(" ",""))
if str_3 != "":
print(miss_let, "is missing letters", str_3)
else:
print(miss_let,"uses all the letters")

Output

zzz is missing letters abcdefghijklmnopqrstuvwxy


subdermatoglyphic is missing letters fjknqvwxz
the quick brown fox jumps over the lazy dog uses all the letters
>>>

You might also like