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)