[Python] Checkio Solution 解答 – Secret Message



Ever tried to send a secret message to someone without using the postal service? You could use newspapers to tell your secret. Even if someone finds your message, it's easy to brush them off and that its paranoia and a bogus conspiracy theory. One of the simplest ways to hide a secret message is to use capital letters. Let's find some of these secret messages.

You are given a chunk of text. Gather all capital letters in one word in the order that they appear in the text.

For example: text = "How are you? Eh, ok. Low or Lower? Ohhh.", if we collect all of the capital letters, we get the message "HELLO".






A text as a string (unicode).



The secret message as a string or an empty string.



0 < len(text) ≤ 1000
all(ch in string.printable for ch in text)


Source: https://py.checkio.org

My Solution:

def find_message(text): 
  import string 
  ans = "" 
  for ch in text: 
    if ch in string.ascii_uppercase: 
      ans += ch 
  return ans


I found that when I knew that I could import some modules to solve a problem, it would not take too long to solve the problem. This lets me notice that how powerful modules are. As long as you use the right module, your file size can be minimized and you can be more efficient.

Copyright © Vantopics