0% found this document useful (0 votes)
37 views3 pages

DSA Assignment 02

Uploaded by

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

DSA Assignment 02

Uploaded by

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

//DSA Assignment 02

def f1(s):
word_list=[Link]()
print("Word list: ",word_list)
longest_word=max(word_list,key=len)
print("Longest word: ",longest_word)

def f2(s):
char=input("Enter character to check frequency of occurence: ")
res={char:[Link](char)}
print(f"Frequency of occurence of character'{char}':",res[char])

def f3(s):
s=[Link]().replace(" ","")
if s==s[::-1]:
print("Given string is palindrome.")
else:
print("Given string is not palindrome.")

def f4(s):
sub=input("Enter substring: ")
index=[Link](sub)
if index !=-1:
print(f"Index of the first appearance of '{sub}':",index)
else:
print(f"'{sub}'not found in the string.")

def f5(s):
word_list=[Link]()
print("word list: ",word_list)
word_count={word: word_list.count(word) for word in set(word_list)}
print("Count the occurrences of each word in the given string: ")
for word,count in word_count.items():
print(f"{word}:{count}")

s=input("Enter strig: ")

while True:
print("\nChoose an operation:")
print("1. To display word with the longest length")
print("2. To determine the frequency of occurrence of a particular character")
print("3. To check whether the given string is palindrome or not")
print("4. To display index of the first appearance of the substring")
print("5. To count the occurrences of each word in the given string")
print("6. Exit")

choice = input("Enter your choice (1/2/3/4/5/6): ")

if choice == '1':
f1(s)
elif choice == '2':
f2(s)
elif choice == '3':
f3(s)
elif choice == '4':
f4(s)
elif choice == '5':
f5(s)
elif choice == '6':
print("Exiting the program.")
break
else:
print("Invalid choice. Please enter a valid option (1/2/3/4/5/6).")

You might also like