Lambda pandrimole


#1

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


#2
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 is_palindrome.call('01011010')    # true
def is_palindrome(phrase)
    phrase == phrase.reverse
end

is_palindrome('01011010')    # true

#3

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