Created
April 14, 2010 16:46
-
-
Save quandyfactory/366041 to your computer and use it in GitHub Desktop.
Determine whether two strings are anagrams.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def anagram(string1, string2, ignore_whitespace=False): | |
"""Determines whether two strings are anagrams.""" | |
if ignore_whitespace==True: | |
import re | |
string1, string2 = re.sub('\s', '', string1), re.sub('\s', '', string2) | |
if len(string1) != len(string2): return False | |
list1, list2 = [c for c in string1].sort(), [c for c in string2].sort() | |
if list1 != list2: return False | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment