1. Python function that takes a list of words and return the longest word and the length of the longest one

In [4]:
def find_longest_length(my_list):
   max_length = len(my_list[0])
   temp = my_list[0]

   for element in my_list:
      if(len(element) > max_length):

         max_length = len(element)
         temp = element
   return max_length

my_list = ["Vijay", "Rajesh", "Gangaraju", "Rajagopal"]
print("The list is :")
print(my_list)
print("The result is :")
print(find_longest_length(my_list))
The list is :
['Vijay', 'Rajesh', 'Gangaraju', 'Rajagopal']
The result is :
9

2. Python function to remove the nth index character from a nonempty string.

In [7]:
def remove_nth(str, index):
    new_str = str[:index] + str[index+1:]
    return new_str
  
print(remove_nth('Printss',6))
print(remove_nth('Scdea',4))
Prints
Scde

3. Python function to get the last part of a string before a specified character.

In [29]:
# initializing string
test_string = "welcome to the Scde training"
 
# initializing split word
spl_word = 'S'
 
 
# using split()
# Get String after substring occurrence
res = test_string.split(spl_word, 1)
 
# print result
print(res[1])
cde training

4. Python function to sort a string lexicographically.

In [12]:
def sortStringInLexo(string):
        words = string.split()
        words.sort()
        for word in words:
                print( word )
                                 
if __name__ == '__main__':
        string = "welcome to the Scde training"
        sortStringInLexo(string)
Scde
the
to
training
welcome

5. Python function to remove spaces from a given string.

In [16]:
# remove spaces using remove function
def remove(string_input): 
    return "".join(string_input.split()) 
      
# Driver Program 
string_input= ' welcome to the Scde training'
print(remove(string_input))
welcometotheScdetraining
In [ ]: