-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3]fds_program_for_string_opration_length.py
66 lines (59 loc) · 1.79 KB
/
3]fds_program_for_string_opration_length.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
str=" "
str=input("Enter String: ")
def long_len():
str_list=[]
long_len=[]
str_list=str.split(" ")
for i in str_list:
long_len.append(len(i))
long_len.sort(reverse=True)
print(max(long_len))
def freq_char():
c=input("Enter Character for Finding its Frequency in String")
print("C=",c)
g=str.count(c)
print(g)
def str_pali():
m=str[::-1]
print(m)
if str==m:
print("String is Palindrome")
else:
print("String is not Palindrome")
def index_substr():
print("Enter Character for Finding its Frequency in String")
str_sub = input()
list_str = str.split(" ")
for i in range(len(list_str)):
if str_sub==list_str[i]:
print(str)
print(i)
break
def freq_word():
list_str=str.split(" ")
print("****Count if each word in String*****")
for i in range(len(list_str)):
print(list_str[i],list_str.count(list_str[i]))
if __name__ == '__main__':
print("*****Take Input*****")
while(True):
print("1. To Display Word with the Longest Length")
print("2. To Determine the Frequency of Occurrence of Particular Character in the String")
print("3. To check whether given String is Palidrome or not")
print("4. To Display Index of First Appearance of the Substring")
print("5. To Count the Occurrence of each word in a given String")
print("6. Exit")
print("Enter Your Choice")
ch=int(input())
if(ch==1):
long_len()
if(ch==2):
freq_char()
if(ch==3):
str_pali()
if(ch==4):
index_substr()
if(ch==5):
freq_word()
if(ch==6):
exit()