I noticed that a different order of while loop conditions gave me the different results:
while (s[l] == s[r] and l >= 0 and r < len(s)):