Lambda pandrimole


Hi, how can I creat a funtion that give true or false pandrimole, using lambda ?

is_palindrome = lambda w: return w == w[::-1]

But a function can serve the same end and likely use less resources.

def is_palindrome(phrase):
    return phrase == phrase[::-1]

Oops! That’s Python. My bad. Let’s try that again…

is_palindrome = lambda { |phrase| phrase == phrase.reverse }

puts'01011010')    # true
def is_palindrome(phrase)
    phrase == phrase.reverse

is_palindrome('01011010')    # true


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.