Python Interview coding 5 With Funny Example
🔄 String Anagram Check: Are Two Strings Anagrams? (Python Solution) An anagram is when two words contain the same letters in a different order. For example, "listen" and "silent" are anagrams. 🧐 In this blog, we’ll explore different ways to check for anagrams in Python and discuss real-life applications where this can be useful! 🚀 🛠️ Method 1: Sorting Approach The simplest way to check if two strings are anagrams is by sorting their characters and comparing them. def is_anagram_sorting(str1, str2): return sorted(str1) == sorted(str2) # Sort and compare # Example Usage word1 = "listen" word2 = "silent" print(f"Are '{word1}' and '{word2}' anagrams? {is_anagram_sorting(word1, word2)}") # Output: True 🔍 Explanation (Line-by-Line) sorted(str1) → Sorts the letters of the first string. sorted(str2) → Sorts the letters of the second string. ...