John Salerno a écrit :
Bruno Desthuilliers wrote:
def encrypt_quote(original):
# Since it's here that we define that the new letters
# will be uppercase only, it's our responsability
# to handle any related conditions and problems
# The other functions shouldn't
Can someone tell me what's happening here. This is my code:
PUNCT_SPACE_SET = set(string.punctuation + string.whitespace)
def filter_letters(original):
return ''.join(set(original) - PUNCT_SPACE_SET)
'original' is a string. The above works as expected, but when I change
it to
return
Em Ter, 2006-05-16 às 20:25 +, John Salerno escreveu:
it doesn't seem to work. The full code is below if it helps to understand.
Why doesn't it work? What does it do, what did you expect it to do?
''.join(set('hi'))
'ih'
''.join(set('HI'))
'IH'
''.join(set('hiHI'))
'ihIH'
Felipe Almeida Lessa wrote:
Em Ter, 2006-05-16 às 20:25 +, John Salerno escreveu:
it doesn't seem to work. The full code is below if it helps to understand.
Why doesn't it work? What does it do, what did you expect it to do?
If you run the whole script with the first line (the one not
John Salerno wrote:
def encrypt_quote(original):
original_letters = filter_letters(original)
You call filter_letters() which makes upper() on all letters, so
original_letters contain only uppercase letters.
new_letters = list(string.ascii_uppercase)
while True:
Michal Kwiatkowski wrote:
And here you're translating 'original' (which contains a lot of
lowercase letters) with use of trans_table that maps only uppercase
characters. This return should be:
return original.upper().translate(trans_table)
Thank you!!! :)
--
John Salerno wrote:
Can someone tell me what's happening here. This is my code:
PUNCT_SPACE_SET = set(string.punctuation + string.whitespace)
def filter_letters(original):
return ''.join(set(original) - PUNCT_SPACE_SET)
'original' is a string. The above works as expected,
John Salerno a écrit :
Can someone tell me what's happening here. This is my code:
PUNCT_SPACE_SET = set(string.punctuation + string.whitespace)
def filter_letters(original):
return ''.join(set(original) - PUNCT_SPACE_SET)
'original' is a string. The above works as expected, but
Bruno Desthuilliers wrote:
def encrypt_quote(original):
# Since it's here that we define that the new letters
# will be uppercase only, it's our responsability
# to handle any related conditions and problems
# The other functions shouldn't have to even know this.
John Salerno wrote:
Some code, with a request to get case working.
Others have shown you where the bug was.
You might want to change encrypt_quote like this:
XXX def encrypt_quote(original):
def encrypt_quote(original, casemap=True):
XXX original_letters = filter_letters(original)
if
John Salerno [EMAIL PROTECTED] writes:
Now, I know the actual upper() function works, but I can't understand
if there's a problem with *when* it's being called, or what's being
done with it to get the second result above.
You are translating original which still has lower case letters:
11 matches
Mail list logo