Python Interview Questions Series-1
In this article, we are going to discuss the palindrome probability for a given string.
A palindrome is a word, number, phrase, or another sequence of characters that reads the same backward as forward, such as madam or racecar.
Let's get into the scenario question coding:-
def check_probability_of_palindrome(s)
dictonary1=dict()
for i in list(s):
if i in dictonary1:
dictonary1[i]+=1
else:
dictonary1[i]=1
k=[]
for i,j in dictonary1.items():
k.append(j)
k1=[]
for i in k:
if i%2!=0:
k1.append(i)
if len(k1)==1:
print(True)
else:
print(False)
# check
check_probability_of_palindrome("abb")
>>> True
## other examples
# Input : "mdaam"
# output: true
# Input : "abb"
# Output : true
# Input : "civic"
# output : true
# input : "rock"
# output : false:
That's all for now...
This Code might look naive but serves the purpose.
Note:- If anyone has a better approach to generalizing this code happy to embed it in my script.
That’s all for now…Happy Learning….
Please do like and follow back my profile…Don't forget to Comment…
Engineering Graduate Assistant at University of Arkansas
1 年Hey!, I need someone to help me. I really want to be a genius in python. I have have the interest but I think i need help ??
Cloud Data Engineer || Blogger || Medium writings
2 年Pawan Kumar K.