Python : Check if Two Sentences are Reversed

Опубликовано: 18 Июль 2026
на канале: Grow with Data
256
12

Video 112: In this tutorial, we delve into the task of checking if two sentences are reversed.

You are given two sentences, and the objective is to determine whether they are the reverse of each other. A sentence is considered the reverse of another if, when the words in one sentence are reversed, they form the exact words in the other sentence.

We address this challenge using two different approaches:

** Approach 1: General Looping Logic **
In this method, we iterate through the strings at the word level and compare each word with the corresponding word from the other sentence using the index position in reverse order. If the words do not match, the function returns False.

** Approach 2: Using reverse() Function **
In this approach, we split the second sentence into a list of words, reverse the list, and then convert it back to a string. If the converted string matches the first sentence, then the sentences are considered reversed. Otherwise, the function returns False.

For a comprehensive understanding and a hands-on demonstration, be sure to watch the entire video. Happy coding!

code: https://github.com/jeganpillai/python...

Follow me on,
Website : https://growwithdata.co/
YouTube :    / @growwithdata  
TikTok :   / growwithdata  
LinkedIn :   / growwithdata  
Facebook :   / growwithdata.co  
twitter :   / growwithdata_co  
WhatsApp : https://whatsapp.com/channel/0029VaF8...
Instagram :   / growwithdata.co  


#recursive #countingalgorithm #list #looping #listmanipulation #uniquesubstring #longestsubstring #slicing #lineartimecomplexity #python #pythonquestions #pythontest #pythonprogramming #pythontutorial #python3 #pythonforbeginners #interviewquestions #interview #dataengineers #deinterview #pythoninterview #interviewquestions #leetcode #placementpreparation #meta #google #facebook #apple #netflix #amazon #google #faang #maanga #dataengineers #alphanumeric #nonalphanumeric #growwithdata #set #split #remove #pythonfunctions