-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpalindrome
46 lines (40 loc) · 1.47 KB
/
palindrome
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def substring(s): # To display all the possible substrings
for i in range(len(s)):
for j in range(i+1,len(s)+1):
string=s[i:j]
print(string)
i=i+1
s=str(input("Enter string : "))
a=substring(s)
def K_len(): # To display those substrings whose length is K
for i in range(len(s)):
for j in range(i+1,len(s)+1):
string=s[i:j]
if len(string)==K:
print(string)
K=int(input("Enter the length of the substring : "))
Length=K_len()
def K_Ndistinct(): # To display those substrings whose length is K and has N distinct characters
N=int(input("Enter the no: of distinct characters in the substring : "))
for i in range(len(s)):
for j in range(i+1,len(s)+1):
string=s[i:j]
Set=set(string)
if len(string)==K and len(Set)==N:
print(string)
print("Substrings whose length is",K,"and which has",N,"distinct characters is absent")
K_Ndistinct()
def palindrome(s): #Palindrome
for i in range(len(s)+1):
for j in range(i+1,len(s)+1):
string=s[i:j]
'''n=string'''
r=string[ : :-1]
count=0
if (r==string):
print(string," , ")
count+=1
if count==0:
print("No palindromes present ")
print("The palindrome strings are listed below : ")
palindrome(s)