Post by John SalernoPUNCT_SPACE_SET = set(string.punctuation + string.whitespace)
return ''.join(set(original) - PUNCT_SPACE_SET)
'original' is a string. The above works as expected, but when I change
it to
return ''.join(set(original.upper()) - PUNCT_SPACE_SET)
it doesn't seem to work. The full code is below if it helps to understand.
import string
import random
import itertools
PUNCT_SPACE_SET = set(string.punctuation + string.whitespace)
return encrypt_quote(quote).split('|')
original_letters = filter_letters(original)
new_letters = list(string.ascii_uppercase)
random.shuffle(new_letters)
trans_letters = ''.join(new_letters)[:len(original_letters)]
trans_table = string.maketrans(original_letters, trans_letters)
break
return original.translate(trans_table)
return ''.join(set(original) - PUNCT_SPACE_SET)
#return ''.join(set(original.upper()) - PUNCT_SPACE_SET)
return False
return True
print convert_quote("The past is not dead. In fact, it's not even
past.|William Faulkner")
Not exactly sure why you think its not working. When you create a set
from the original.upper() you get a smaller number of characters because
you no longer get both 'T' and 't' as well as 'I' and 'i' as you do in
the lower case version of the string.
Post by John Salernoset(original.split('|')[0])
set(['a', ' ', 'c', 'e', 'd', "'", 'f', 'i', 'h', ',', 'o', 'n', 'p', 's', 'T',
'v', 'I', '.', 't'])
Post by John Salernoset(original.split('|')[0].upper())
set(['A', ' ', 'C', 'E', 'D', "'", 'F', 'I', 'H', ',', 'O', 'N', 'P', 'S', 'T',
'V', '.'])
sets can only contain "unique" entries. Letters that are repeated only get
added once. When you do .upper() you convert lowercase 't' to 'T' and lower
case 'i' to 'I' so that letter only gets added to the set a single time.
Hope info helps.
Larry Bates