[ Write a program that extract words starting with Vowel From A list ``` ]
# initializing list
test_list = ["have", "a", "good", "one"]
# printing original list
print("The original list is : " + str(test_list))
res = []
vow = "aeiou"
for sub in test_list:
flag = False
# checking for begin char
for ele in vow:
if sub.startswith(ele):
flag = True
break
if flag:
res.append(sub)
# printing result
print("The extracted words : " + str(res))
write a program to replace vowels by next vowel using list comprehension + zip()
test_str = 'helloworld'
print("The original string is : " + str(test_str))
vow = 'a e i o u'.split()
temp = dict(zip(vow, vow[1:] + [vow[0]]))
res = "".join([temp.get(ele, ele) for ele in test_str])
print("The replaced string : " + str(res))
write a program to reverse words of string
def rev_sentence(sentence):
words = sentence.split(' ')
reverse_sentence = ' '.join(reversed(words))
return reverse_sentence
if __name__ == "__main__":
input = 'have a good day'
print (rev_sentence(input))
write a program to find the least Frequent Character in String
test_str = "helloworld"
print ("The original string is : " + test_str)
all_freq = {}
for i in test_str:
if i in all_freq:
all_freq[i] += 1
else:
all_freq[i] = 1
res = min(all_freq, key = all_freq.get)
print ("The minimum of all characters in the given word is : " + str(res))
write a program to find the most frequent element in a list
def most_frequent(List):
counter = 0
num = List[0]
for i in List:
curr_frequency = List.count(i)
if(curr_frequency> counter):
counter = curr_frequency
num = i
return num
List = [2, 1, 2, 2, 1, 3]
print(most_frequent(List))
write a program insert character after every character pair
# initializing string
test_str = "HellowWorld"
print("The original string is : " + test_str)
res = ', '.join(test_str[i:i + 2] for i in range(0, len(test_str), 2))
print("The string after inserting comma after every character pair : " + res)
write a program to remove i-th indexed character from a string
def remove(string, i):
a = string[ : i]
b = string[i + 1: ]
return a + b
# Driver Code
if __name__ == '__main__':
string = "HellowWorld"
# Remove nth index element
i = 5
# Print the new string
print(remove(string, i))