a=[]
n= int(input("Enter the number of elements in list:"))
for x in range(0,n):
element=input("Enter element" + str(x+1) + ":")
a.append(element)
max1=len(a[0])
temp=a[0]
for i in a:
if(len(i)>max1):
max1=len(i)
temp=i
print("The longest word is:")
print(temp)
print("the length of the longest word is:", len(temp))
Enter the number of elements in list:4 Enter element1:i Enter element2:had Enter element3:an Enter element4:apple The longest word is: apple the length of the longest word is: 5
def remove_ch(str, n):
first_part= str[:n]
last_part= str[n+1:]
return first_part+last_part
str = input("enter the string:")
n=int(input("enter the index of character to be removed:"))
print("modified string:",remove_ch(str,n))
enter the string:python enter the index of character to be removed:3 modified string: pyton
str1= "learn-python/programming"
print(str1.rsplit('/')[0])
print(str1.rsplit('-')[0])
learn-python learn
def lexico_sort(s):
return sorted(sorted(s), key= str.upper)
s= input("enter the string:")
print("modified string:",lexico_sort(s) )
enter the string:python modified string: ['h', 'n', 'o', 'p', 't', 'y']
def remove(str):
return str.replace(" ", "")
str= input(" enter a string ")
print("modified string:", remove(str))
enter a string " hello python " modified string: "hellopython"