ChecjIO: Verify Anagrams
来源:互联网 发布:网络大电影报批流程 编辑:程序博客网 时间:2024/05/21 14:58
An anagram is a type of word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once. Two words are anagrams to each other if we can get one from another by rearranging the letters. Anagrams are case-insensitive and don't take account whitespaces. For example: "Gram Ring Mop" and "Programming" are anagrams. But "Hello" and "Ole Oh" are not.
You are given two words or phrase. Try to verify are they anagrams or not.
Input: Two arguments as strings.
Output: Are they anagrams or not as boolean (True or False)
Example:
verify_anagrams("Programming", "Gram Ring Mop") == True
verify_anagrams("Hello", "Ole Oh") == False
verify_anagrams("Kyoto", "Tokyo") == True
How it is used: Anagramming can be a fun way to train your brain, but they have and another application. Psychologists use anagram-oriented tests, often called "anagram solution tasks", to assess the implicit memory. Anagrams are connected to pseudonyms, by the fact that they may conceal or reveal, or operate somewhere in between like a mask that can establish identity. In addition to this, multiple anagramming is a technique sometimes used to solve some kinds of cryptograms.
Precondition: 0 < |first_word| < 100;
0 < |second_word| < 100;
Words contain only ASCII latin letters and whitespaces.
一道水题,将一个单词更换顺序组成另一个单词,大小写不计。def verify_anagrams(first_word, second_word): first_word = first_word.lower() second_word = second_word.lower() A = ''.join(sorted(list(first_word))) B = ''.join(sorted(list(second_word))) if A.strip() == B.strip(): return True return Falseif __name__ == '__main__': #These "asserts" using only for self-checking and not necessary for auto-testing assert isinstance(verify_anagrams("a", 'z'), bool), "Boolean!" assert verify_anagrams("Programming", "Gram Ring Mop") == True, "Gram of code" assert verify_anagrams("Hello", "Ole Oh") == False, "Hello! Ole Oh!" assert verify_anagrams("Kyoto", "Tokyo") == True, "The global warming crisis of 3002"
def verify_anagrams(first_word, second_word):
return sorted(first_word.replace(" ","").lower()) == sorted(second_word.replace(" ","").lower())
if __name__ == '__main__': #These "asserts" using only for self-checking and not necessary for auto-testing assert isinstance(verify_anagrams("a", 'z'), bool), "Boolean!" assert verify_anagrams("Programming", "Gram Ring Mop") == True, "Gram of code" assert verify_anagrams("Hello", "Ole Oh") == False, "Hello! Ole Oh!" assert verify_anagrams("Kyoto", "Tokyo") == True, "The global warming crisis of 3002"
def verify_anagrams(first_word, second_word): first_word = first_word.lower() second_word = second_word.lower() A = ''.join(sorted(list(first_word))) B = ''.join(sorted(list(second_word))) if A.strip() == B.strip(): return True return Falseif __name__ == '__main__': #These "asserts" using only for self-checking and not necessary for auto-testing assert isinstance(verify_anagrams("a", 'z'), bool), "Boolean!" assert verify_anagrams("Programming", "Gram Ring Mop") == True, "Gram of code" assert verify_anagrams("Hello", "Ole Oh") == False, "Hello! Ole Oh!" assert verify_anagrams("Kyoto", "Tokyo") == True, "The global warming crisis of 3002"def verify_anagrams(first_word, second_word):
return sorted(first_word.replace(" ","").lower()) == sorted(second_word.replace(" ","").lower())
if __name__ == '__main__': #These "asserts" using only for self-checking and not necessary for auto-testing assert isinstance(verify_anagrams("a", 'z'), bool), "Boolean!" assert verify_anagrams("Programming", "Gram Ring Mop") == True, "Gram of code" assert verify_anagrams("Hello", "Ole Oh") == False, "Hello! Ole Oh!" assert verify_anagrams("Kyoto", "Tokyo") == True, "The global warming crisis of 3002"
0 0
- ChecjIO: Verify Anagrams
- Verify
- Verify
- verify
- Anagrams
- Anagrams
- Anagrams
- Anagrams
- Anagrams
- Anagrams
- Anagrams
- Anagrams
- Anagrams
- Anagrams
- Anagrams
- Anagrams
- Anagrams
- Anagrams
- Emgucv_Motion_Detection_MotionHistory_Human_Activity_in_video
- mysql 查询 表连接详解
- 【笔记】Qt程序在Windows、OS X、CentOS、Ubuntu下的打包处理
- 长方柱类
- Picasso轻松实现圆角图片
- ChecjIO: Verify Anagrams
- java基础学习总结——public,private,protected,和默认的区别
- pyinstaller打包exe错误
- python核心编程学习笔记-2016-08-28-01-习题18-4和习题18-9
- chrome浏览器打开百度http出现红叉
- 指向学生类的指针
- 用javah导出类的头文件,Not a valid class name或者错误: 找不到 'HelloNDK' 的类文件
- linux学习心得
- 静态方法和实例化方法的区别