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(["apple", "samsung", "oneplus"])
print("\nLongest word: ",result[1])
print("Length of the longest word: ",result[0])
Longest word: samsung Length of the longest word: 7
def remove_char(str,n):
first_part = str[:n]
last_part = str[n+1:]
return first_part + last_part
print(remove_char('delicious', 5))
print(remove_char('delicious', 8))
print(remove_char('delicious', 2))
delicous deliciou deicious
str = "https://www.python.exercise.com/programming.knowledging."
print(str.split('.', 1)[0])
print(str.split('/', 1)[0])
https://www https:
string = "do not play outside in the sun for a long time"
modified = string.replace(" ","")
print(modified)
donotplayoutsideinthesunforalongtime
list_one = ["gum", "tooth", "enamel", "dentist", "braces"]
print("the original list before sorting is:", list_one)
list_one.sort()
print("the original list after sorting is:", list_one)
the original list before sorting is: ['gum', 'tooth', 'enamel', 'dentist', 'braces'] the original list after sorting is: ['braces', 'dentist', 'enamel', 'gum', 'tooth']