CMU Coding Bootcamp
at main 874 B view raw
1def sameChars(s1: str, s2: str) -> bool: 2 """Check if two strings have the same characters regardless of order or count.""" 3 if not (isinstance(s1, str) and isinstance(s2, str)): 4 return False 5 c1 = list(set(s1)) 6 c2 = list(set(s2)) 7 c1.sort() 8 c2.sort() 9 print(c1, c2) 10 return c1 == c2 11 12 13print("Testing sameChars()...", end="") 14assert sameChars("abc", "bac") == True 15assert sameChars("aaaaabbbbbbccccc", "abc") == True 16assert sameChars("abc", "ba") == False 17assert sameChars("ba", "abc") == False 18assert sameChars("AAAAAAaaaa", "Aa") == True 19assert sameChars("NNN", "n") == False 20assert sameChars("123", "123") == True 21assert sameChars("", "a") == False 22assert sameChars("", "") == True 23# assert sameChars(14, "14") == False # this check passes but if I don't comment it I get an editor warning since I've typed the function 24print("Passed!")