DEV Community

Cover image for Monthly Challenge #1: Palindrome 🔤
Sonny Li for Codédex

Posted on • Updated on

Monthly Challenge #1: Palindrome 🔤

Welcome to Codédex's first ever Monthly Twitter Challenge! This one is created by our SWE Intern, @asiqurrahman. 🙌

Palindrome:

A word, sentence, or number that reads the same forward or backward (e.g., racecar, civic, and 121).

Challenge:

Create a Python function that:

  1. Takes in a string as a parameter.
  2. Checks if it's a palindrome.
  3. Returns True if it is or False if it's not.

Requirements:

  • 📦 Don’t use any packages.
  • 💬 Make sure to comment the code.

Post your program screenshot in the Twitter thread.

And we will pick a random winner by noon this Friday. The prize is a free Codédex tee and bragging rights! 🏆


Update:

We have a winner to the Codédex Monthly Challenge: Palindrome! 🥁...

Congrats to Michael Gonzalez! 🇪🇨

The reasons being:

  • Solution covers string & number
  • Good comments
  • Good breakdown of the functions
  • First to post bonus

Here's the solution:

Oldest comments (10)

Collapse
 
bobliuuu profile image
Jerry Zhu

So cool! Can't wait to see all the solutions

Collapse
 
sonnynomnom profile image
Sonny Li

Let's go Jerry!

Collapse
 
peter profile image
Peter Kim Frank

Excited to follow along with this thread and challenge series :)

Collapse
 
sonnynomnom profile image
Sonny Li

Haha thanks Peter! 🤙

Collapse
 
frederik_vl profile image
Frederik Van Lierde

Why only Python, why not open to all coding languages ;)

Ex. Solution in C#

public static bool IsPalladium(this string text)
        {
            return text.SequenceEqual(text.Reverse());
        }
Enter fullscreen mode Exit fullscreen mode
Collapse
 
sonnynomnom profile image
Sonny Li

True! Only doing it for Python for now since codedex.io only has Python :(

Also, one line answer! 🙌 Shared the the team!

Collapse
 
frederik_vl profile image
Frederik Van Lierde

I adore one line functions ;)

Collapse
 
abubakrchan profile image
AbubakrChan

nice

Collapse
 
liad0205 profile image
Liad0205

I guess..

def IsPalindrome(txt: str):
    length = len(txt)
    oddOrEven = 1 if length%2 else 0
    return txt[:length//2] == txt[length:length//2-1+oddOrEven:-1]

forTheGiggles = lambda txt: txt == txt[::-1]
Enter fullscreen mode Exit fullscreen mode
Collapse
 
sonnynomnom profile image
Sonny Li • Edited

We have a winner to the Codédex Monthly Challenge: Palindrome! 🥁...

Congrats to Michael Gonzalez! 🇪🇨

The reasons being:

  • Solution covers string & number
  • Good comments
  • Good breakdown of the functions
  • First to post bonus

Here's the solution: