-9

Write a function that checks whetherb two words are anagrams. Two words are anagrams if they contain the same latters. (Example: silent and listen). The header of the function is : def isAnagram(s1, s2):

(Hint: Obtain two lists for the 2 strings. Sort the lists and check if two lists are identical)

Write a test program that promts the user to enter two stringd and if theyre anagrams, display 'are anagram' otherwise, 'are not anagram'.

4

1 回答 1

3

提示准确地告诉您需要做什么。

list()函数将帮助您将字符串转换为列表。 http://docs.python.org/library/functions.html#list

然后查找列表方法sort()http://docs.python.org/tutorial/datastructures.html

然后查找列表比较。 http://docs.python.org/tutorial/datastructures.html#comparing-sequences-and-other-types

或者只是查找sorted() http://docs.python.org/library/functions.html#sorted

于 2012-04-25T15:44:02.077 回答