Skip to main content
fixed spelling and punctuation; added code formatting and MathJax
Source Link
while len(string1) == len(string2):

Why are you useing whileusing while here instead of ifif?

I think itsit's "ugly" to have a function that has mixed return types, in your case booleans or a string.

You dontdon't need to test the lenghtlength before you check if the sorted lists are the same.

Big-o of this would be the Big-o of whatever sorting function sorted are useingusing, iI think it is timsort in python so the big-o whouldwould be n log n\$n \log n\$.

If they are asking for a python dev it's good to use builltins becousebecause that shows you know the languishlanguage.

InstedInstead of useing a ifan if, you could just return the value of the boolean operation. iI would probably implement it something like this.

def is_anagram(s1,s2):
    return sorted(s1) == sorted(s2)
while len(string1) == len(string2):

Why are you useing while here instead of if?

I think its "ugly" to have a function that has mixed return types, in your case booleans or a string.

You dont need to test the lenght before you check if the sorted lists are the same.

Big-o of this would be the Big-o of whatever sorting function sorted are useing, i think it is timsort in python so the big-o whould be n log n.

If they are asking for a python dev it's good to use builltins becouse that shows you know the languish.

Insted of useing a if, you could just return the value of the boolean operation. i would probably implement it something like this.

def is_anagram(s1,s2):
    return sorted(s1) == sorted(s2)
while len(string1) == len(string2):

Why are you using while here instead of if?

I think it's "ugly" to have a function that has mixed return types, in your case booleans or a string.

You don't need to test the length before you check if the sorted lists are the same.

Big-o of this would be the Big-o of whatever sorting function sorted are using, I think it is timsort in python so the big-o would be \$n \log n\$.

If they are asking for a python dev it's good to use builltins because that shows you know the language.

Instead of useing an if, you could just return the value of the boolean operation. I would probably implement it something like this.

def is_anagram(s1,s2):
    return sorted(s1) == sorted(s2)
Source Link
baot
  • 175
  • 6

while len(string1) == len(string2):

Why are you useing while here instead of if?

I think its "ugly" to have a function that has mixed return types, in your case booleans or a string.

You dont need to test the lenght before you check if the sorted lists are the same.

Big-o of this would be the Big-o of whatever sorting function sorted are useing, i think it is timsort in python so the big-o whould be n log n.

If they are asking for a python dev it's good to use builltins becouse that shows you know the languish.

Insted of useing a if, you could just return the value of the boolean operation. i would probably implement it something like this.

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