Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways

Palindrome in Python | Python for Data Science | Day 6

Ciao amici! 
The Data Monk community is back with another new topic for you. It’s time for some programming, as we discuss the palindrome program in python. But, before you open your notebooks, let’s discuss what really is a palindrome

Palindrome in Python

Palindrome is a string that spells the same when read backwards. To give it a try, look at the image above. Let’s intuitively discuss how we can figure out if a string is a palindrome or not.

The most naive approach is to check if a string is a palindrome or not:

STEP 1: Reverse the string.

STEP 2: Check if reverse is equal to the original string.

STEP 3: If reverse = original string, it’s a palindrome. Else, not.

Now, let’s implement the code for this approach:

Palindrome in Python
Palindrome in Python

Another approach to figure out if a string is palindrome or not is to iteratively store each character of the string in a new variable and then check if the original string is equal to the reversed string.

Check the code below to implement the approach:

Let’s discuss another approach. In this one, we use two status pointers. The first pointer is placed on the left-most index and the second  is placed on the right-most index. If we start matching the variables on these pointers and then update the status of the flag variable accordingly, we can find out if the given string is palindrome or not. The code for this approach is given below:

A homework for you: Visit http://componentsprogramming.com/palindromes/ to analyze the time complexity of various palindrome programs and find out the best approach.

Make sure you revise the codes given above and attempt the following question:

The questions have been answered for your convenience. But you know the drill, try these on your own first.

The Data Monk Interview Books – Don’t Miss

Now we are also available on our website where you can directly download the PDF of the topic you are interested in. At Amazon, each book costs ~299, on our website we have put it at a 60-80% discount. There are ~4000 solved interview questions prepared for you.

10 e-book bundle with 1400 interview questions spread across SQL, Python, Statistics, Case Studies, and Machine Learning Algorithms – Ideal for 0-3 years experienced candidates

23 E-book with ~2000 interview questions spread across AWS, SQL, Python, 10+ ML algorithms, MS Excel, and Case Studies – Complete Package for someone between 0 to 8 years of experience (The above 10 e-book bundle has a completely different set of e-books)

12 E-books for 12 Machine Learning algorithms with 1000+ interview questions – For those candidates who want to include any Machine Learning Algorithm in their resume and to learn/revise the important concepts. These 12 e-books are a part of the 23 e-book package

Individual 50+ e-books on separate topics

Important Resources to crack interviews (Mostly Free)

There are a few things which might be very useful for your preparation

The Data Monk Youtube channel – Here you will get only those videos that are asked in interviews for Data Analysts, Data Scientists, Machine Learning Engineers, Business Intelligence Engineers, Analytics managers, etc.
Go through the watchlist which makes you uncomfortable:-

All the list of 200 videos
Complete Python Playlist for Data Science
Company-wise Data Science Interview Questions – Must Watch
All important Machine Learning Algorithm with code in Python
Complete Python Numpy Playlist
Complete Python Pandas Playlist
SQL Complete Playlist
Case Study and Guesstimates Complete Playlist
Complete Playlist of Statistics

About TheDataMonkGrand Master

I am the Co-Founder of The Data Monk. I have a total of 6+ years of analytics experience 3+ years at Mu Sigma 2 years at OYO 1 year and counting at The Data Monk I am an active trader and a logically sarcastic idiot :)

Follow Me