def longest_word():
list_of_words = input("Enter list of words: ")
length = 0
for words in list_of_words.split():
if len(words) > length:
length = len(words)
longest_word1 = words
print("The Longest word is:",longest_word1,"\nLength of Longest one is:",len(longest_word1))
longest_word()
Enter list of words: Hello friends I am Learning Pyhton Programming The Longest word is: Programming Length of Longest one is: 11
string = input("Enter a Non-Empty String:")
n = int(input("Enter the index of String to be removed:"))
def remove_index(string,n):
start = string[:n]
end = string[n+1:]
return start + end
print("Modified String is:",remove_index(string,n))
Enter a Non-Empty String:Hello guys!!!!! Enter the index of String to be removed:6 Modified String is: Hello uys!!!!!
string_2 = input("Enter the String: ")
character = input("Enter the specified character: ")
if character == "/":
print(string_2.rsplit('/',1)[0])
elif character == "-":
print(string_2.rsplit('-')[0])
elif character == ":":
print(string_2.rsplit(':')[0])
Enter the String: abc.com/xyz-uvw Enter the specified character: - abc.com/xyz
def string_sort(string_input):
stringlist = string_input.split()
stringlist.sort()
string_op = ""
for word in stringlist:
string_op = string_op+word+" "
return string_op
string_ip = input("Enter the String: ")
print("Original String: ",string_ip)
print("Sorted String: ",string_sort(string_ip))
Enter the String: vaishu is eating an orange Original String: vaishu is eating an orange Sorted String: an eating is orange vaishu
string_1 = input("Enter the String: ")
def remove_spaces(string_1):
count = 0
list_1 = []
for i in range(len(string_1)):
if string_1[i] != " ":
list_1.append(string_1[i])
return ''.join(list_1)
print(remove_spaces(string_1))
Enter the String: My name is Mahith Sai MynameisMahithSai