Python bootcamp · Lab 16

Anagram check

mediumStrings12 minLesson: String Methods

Read the question, write Python on the right, then Run or Check.

QuestionHint and solution stay closed until you open them

Read two words (one per line) and print yes if they are anagrams of each other, otherwise no.

Two words are anagrams when they use exactly the same letters, just rearranged. Compare case-insensitively.

Input. Two lines, each one word.

Output. yes or no (lowercase).

Examples

Example 1 — Same letters, different order.
Input
listen
silent
Output
yes
Example 2
Input
hello
world
Output
no
Hint
  1. If you sort the letters of each word, anagrams become identical.
  2. sorted("listen") == sorted("silent") is True. Lowercase both first.
Show correct code

Peek only after you have tried. You can still Check your own version.

a = input().strip().lower()
b = input().strip().lower()
print("yes" if sorted(a) == sorted(b) else "no")
main.pyPython · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.