1. Python function that takes a list of words and return the longest word and the length of the longest one.
2. Python function to remove the nth index character from a nonempty string.
3. Python function to get the last part of a string before a specified character.
4. Python function to sort a string lexicographically.
5. Python function to remove spaces from a given string.
46 is in the range 100 is outside the given range.
def find_longest_word(words_list):
word_len = []
for n in words_list:
word_len.append((len(n), n))
word_len.sort()
return word_len[-1][0], word_len[-1][1]
result = find_longest_word(["Santoor", "Mysore Sandal", "Cinthol", "Rexona"])
print("\nLongest word: ",result[1])
print("Length of the longest word: ",result[0])
Longest word: Mysore Sandal Length of the longest word: 13
def remove_nth(str, index):
new_str = str[:index] + str[index+1:]
return new_str
print(remove_nth('resultss',6))
print(remove_nth('Mathse',5))
results Maths
# initializing string
test_string = "welcome to the DS 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])
training
def sortStringInLexo(string):
words = string.split()
words.sort()
for word in words:
print( word )
if __name__ == '__main__':
string = "welcome to the Data Science Program"
sortStringInLexo(string)
Data Program Science the to welcome
# remove spaces using remove function
def remove(string_input):
return "".join(string_input.split())
# Driver Program
string_input= 'Data Sceince Program with Python'
print(remove(string_input))
DataSceinceProgramwithPython