Knowee
Questions
Features
Study Tools

wo words are anagrams if you can rearrange the letters from one to spell the other. For example, `'hello'` and `'olleh'` are anagrams. You are to write a function called `isAnagram1` which takes two strings and returns `True` if they are anagrams. You can assume that the strings are made up of lowercase alphabets. `isAnagram1` should make use of the `sorted` function.

Question

wo words are anagrams if you can rearrange the letters from one to spell the other. For example, 'hello' and 'olleh' are anagrams. You are to write a function called isAnagram1 which takes two strings and returns True if they are anagrams. You can assume that the strings are made up of lowercase alphabets. isAnagram1 should make use of the sorted function.

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, here is a function that checks if two strings are anagrams using the sorted function:

def isAnagram1(s1, s2):
    return sorted(s1) == sorted(s2)

This function works by sorting the characters in each string and comparing the sorted strings. If the sorted strings are equal, then the original strings are anagrams.

Similar Questions

Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order.An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

An anagram is a word or a phrase made by transposing the letters of another word or phrase; for example, "parliament" is an anagram of "partial men," and "software" is an anagram of "swear oft." Write a program that figures out whether one string is an anagram of another string. The program should ignore white space and punctuation

Given an array of strings strs, group the anagrams together. You can return the answer in any order.An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.Note: Use Structure

You are to write a function called `isAnagram2` that takes two strings and returns `True` if they are anagrams. You can assume that the strings are made up of lowercase alphabets. `isAnagram2` should not use the `sorted` function.- **Hints/Guide**: - `ord` gives you the numeric representation of a character. `ord('a') = 97`, `ord('b') = 98`, `ord('c') = 99`, ..., `ord('y') = 121`, `ord('z') = 122`. - You can only use concepts we have treated in class so far up to lists. No dictionaries. - You cannot import any library. - You cannot use more than 10 variables in your function.

Write a program to check two strings are anagram or not.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.