###1.Fuction to take in a list of words, find the longest word and print the length of the longest word
string=input("Enter a list of names separated by , : ")
list=string.split(",")
largest=0
for i in list:
if len(i)>largest:
largest=len(i)
j=i
print("The longest word is", j, "and it is", largest, "letters long")
Enter a list of names separated by , : tauseef,vikas,rizwan,ranjith The longest word is tauseef and it is 7 letters long
###python function to remove the nth index character from a nonempty string
def remove(string,n):
first=string[:n]
last=string[n+1:]
return first+last
string=input('enter the string:')
n=int(input('enter the index of the character to remove:'))
print("modified string:")
print(remove(string,n))
enter the string:apple enter the index of the character to remove:3 modified string: appe
###3. Function to get the last part of a string before a specified character
Mystr=str(input("Enter a string: "))
n=int(input("Enter the nth character: "))
new_str=""
for i in range(0,len(Mystr)):
if i>n-1:
new_str=new_str+Mystr[i]
print("New string is", new_str)
Enter a string: rizwan Enter the nth character: 2 New string is zwan
###4. Function to sort a string lexicographically
My_str=str(input("Enter a String: "))
New_str=sorted(My_str)
lex=""
for char in New_str:
lex=lex+char
print("The lexicographical order of", My_str, "is", lex)
Enter a String: rizwan The lexicographical order of rizwan is ainrwz
###5. Function to remove spaces from a given string
My_str=str(input("Enter a string: "))
New_str=My_str.replace(" ","")
print(New_str)
Enter a string: I am studying in Malla Reddy college IamstudyinginMallaReddycollege