Unit: Unit 4: Strings, Lists, and Tuples • Interactive Practice
Interactive Python programming tutorial and practice in your browser.
# Determine if two candidate strings are anagrams
word_a = "Conversation"
word_b = "Voices, rant on"
# Clean strings: keep only lowercase letters
clean_a = [ch.lower() for ch in word_a if ch.isalpha()]
clean_b = [ch.lower() for ch in word_b if ch.isalpha()]
# Anagram test: compare sorted character lists
is_anagram = sorted(clean_a) == sorted(clean_b)
print("Cleaned List A:", clean_a)
print("Cleaned List B:", clean_b)
print("Are they anagrams?", is_anagram)