Welcome to Serpia's blog!
Blog Entry
From HAL to IBM
From HAL to IBM
You want to translate the string 'HAL'into:
IBM (Go see the movie, if this doesn't ring a bell ;-)
Solution: Explanation: We will need the string library, therefore it needs to be imported. Next, we'll create a string called HAL and finally we will create a string using the ascii_uppercase string constant ('ABCDEFGHIJKLMNOPQRSTUVWXYZ'). What does [1:] do? It slices the first character. Example: What does [:1] do? All but the first characters are sliced. Example And a new string is created from the sliced strings.
The next line uses the string.maketrans method, it returns a translation table suitable for use in string.translate, which we will use in the next line. Finally the string.translate method returns a copy of the string trans, where all characters have been mapped through the given translation table trans.
Comments
#2
dimitri, January 27, 2008 at 5:11 p.m.:
Speaking of HAL, many of us believed that his name, H-A-L was a play on I-B-M, the next letters in the alphabet. Stanley Kubrick vehemently denied this. HAL, Kubrick said, stood for Heuristic ALgorithmic Computer.
Post a comment
Wow, I never realized that HAL is IBM with each character shifted by one place. Nice catch.