0% found this document useful (0 votes)
6 views2 pages

Palindrome Substring Etc

Uploaded by

ppawar612006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Palindrome Substring Etc

Uploaded by

ppawar612006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

# Functions to find first appearance of the substring----------------->>

def In(element, list1):


flag =0
for i in range(len(list1)):
if element == list1[i]:
flag = 1
if flag == 1:
return True
else:
return False

def first_appe(string, substring):


flag=0
for i in range(len(substring)):
if In(substring[i], string):
flag +=1
if flag==len(substring):
for i in range(len(string)):
if substring[0]==string[i]:
return i
return 0

# Function to reverse the given string---------------------------------->>


def revstr(string):
revstr=""
for i in range(len(string)):
revstr=string[i]+revstr
return revstr

# Function to count the length of given string-------------------------->>


def str_count(str1, char):
count=0
for i in range(len(str1)):
if char==str1[i]:
count+=1
return count

# Function to find word with longest length----------------------------------->>


def max_len(splitL):
global new_str2
len1=0
new_str1=""
for i in range (len(splitL)):
if len1 < len(splitL[i]):
len1=len(splitL[i])
new_str2=new_str1+splitL[i]
return len1

# Function to check given string is palindrome or not withot reversing string-->>


def is_palindrome(str):

for i in range(0, int(len(str)/2)):

if str[i] != str[len(str)-i-1]:

return False

return True
str1= input("Enter string to check palindrome:- ")

if is_palindrome(str1):
print ("Entered string is palindrome")
else:
print("Entered string is not palindrome")

# Palindrome checking using reverse string method----------------->>


if revstr(str1)==str1:
print("Entered string is palindrome(using reverse string method)")
else:
print("Entered string is not a palindrome(Using reverse string method)")
str2= input("Enter sentence to check maximum length of word:")
new=str2.split()
print ("Length: ",max_len(new), "Word: ",new_str2)
str3= input ("Enter string to check perticular character count:")
ch=input ("Enter character: ")
print("Entered character count is: ",str_count(str3, ch))

str4 = input("Enter string to check first appearance of substring: ")


substring= input("Enter substring: ")
print(substring, "is at index: ", first_appe(str4, substring))

You might also like