Skip to content

Instantly share code, notes, and snippets.

@lindsaymarkward
Created March 9, 2015 00:28
Show Gist options
  • Save lindsaymarkward/b5dae3aa1003707de7df to your computer and use it in GitHub Desktop.
Save lindsaymarkward/b5dae3aa1003707de7df to your computer and use it in GitHub Desktop.
Check if a string contains all letters of the alphabet.
"""
Lindsay Ward, 09/03/2015
Quick program to check if a string contains all letters of the alphabet
"""
__author__ = 'sci-lmw1'
test1 = "Playing jazz vibe chords quickly excites my wife."
test2 = "The quick brown fox jumped over the lazy dog."
letterCounts = [0] * 26
# print(ord('a'))
words = test1.lower()
for letter in words:
if 'a' <= letter <= 'z':
# print(letter, ord(letter))
letterCounts[ord(letter) - 97] += 1
# print(letter)
# print(letterCounts)
char = 'a'
allLetters = True
for count in letterCounts:
print(char, count, end='\t')
char = chr(ord(char) + 1)
if count == 0:
allLetters = False
print()
if allLetters:
print("String contains all letters! :)")
else:
print("String does not contain all letters :(")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment