Capitalize first and last letters of each word.

In this program, we will take a string as input and capitalize first and last letters of each word.

Steps to solve the program
  1. Take a string as input.
  2. Capitalize first and last letters of each word using Indexing and upper() function.
  3. Print the output.
				
					#Input string
string = "this is my first program"

for char in string.split(" "):
    #Printing output
    print(char[0].upper() + char[1:-1] + 
          char[-1].upper(), end=" ")
				
			

Output :

				
					ThiS IS MY FirsT PrograM 
				
			

remove spaces from a given string.

calculate the sum of digits of a given string.

Remove spaces from a given string

In this program, we will take a string as input and remove spaces from a given string.

Steps to solve the program
  1. Take a string as input.
  2. Create an empty string.
  3. Add every character from the input string to the empty string except spaces.
  4. Print the output.
				
					#Input string
string1 = "python at sqatools"
str1 = ""

for char in string1:
    if char != " ":
        str1 += char

#Printing output
print(str1)
				
			

Output :

				
					pythonatsqatools
				
			

second most repeated word in a given string

capitalize the first and last letters of each word of a given string.

Find the second most repeated word in a string.

In this program, we will take a string as input and find the second most repeated word in a given string.

Steps to solve the program
  1. Take a string as input and create an empty dictionary.
  2. Use for loop to iterate over each word of the string.
  3. Add a word as the key and its occurrences in a string as the value in the dictionary.
  4. Use sorted() and lambda function to sort the dictionary by values.
  5. Print the second most repeated word in a string.
				
					#Input string
string = "ab bc ac ab bd ac nk hj ac"
dictionary = dict()

for char in string.split(" "):
    if char != " ":
        dictionary[char] = string.count(char)

counts_ = sorted(dictionary.items(), key=lambda val: val[1])
#Printing output
print(counts_[-2])
				
			

Output :

				
					('ab', 2)
				
			

find the first repeated word in a given string. 

remove spaces from a given string.

Find the first repeated word in a given string. 

In this program, we will take a string as input and find the first repeated word in a given string. 

Steps to solve the program
  1. Take a string as input and create an empty list.
  2. Add each word from the string to the empty list using for loop.
  3. If a word repeats then break the loop.
  4. Print the output.
				
					#Input string
str1 = "ab bc ca ab bd ca"
temp = []

for word in str1.split():
    if word in temp:
        print("First repeated word: ", word)
        break
    else:
        temp.append(word)
				
			

Output :

				
					First repeated word:  ab
				
			

split a string on the last occurrence of the delimiter. 

find the second most repeated word in a given string

Split a string on last occurrence of delimiter. 

In this program, we will take a string as input and split a string on last occurrence of delimiter.

Steps to solve the program
  1. Take a string as input.
  2. Split the string on the last occurrence of delimiter using rsplit().
  3. Print the output.
				
					#Input string
str1 = "l,e,a,r,n,I,n,g,p,y,t,h,o,n"

#Printing output
print(str1.rsplit(',', 1))
				
			

Output :

				
					['l,e,a,r,n,I,n,g,p,y,t,h,o', 'n']
				
			

count and display the vowels in a string

find the first repeated word in a given string. 

Count the vowels in a string

In this program, we will take a string as input and count the vowels in a string.

Steps to solve the program
  1. Take a string as input.
  2. Create a list containing all the vowels and create a count variable and assign its value equal to 0.
  3. Use for loop to iterate over each character from the string.
  4. If that character is present in the vowels add 1 to the count variable.
  5. Print the output.
				
					#Input string
string = "welcome to Sqatools"
vowels = ["A","E","I","O","U",
         "a","e","i","o","u"]
count = 0

for char in string:
    if char in vowels:
        count += 1

#Printing output
print(count)
				
			

Output :

				
					7
				
			

swap commas and dots in a string.

split a string on the last occurrence of the delimiter. 

Swap commas and dots in a string.

In this program, we will take a string as input and swap commas and dots in a string.

Steps to solve the program
  1. Take a string as input.
  2. Swap commas with dots in the string using replace().
  3. Print the output.
				
					#Input string
string = "sqa,tools.python"

#Replacing , by .
string.replace(",",".")
				
			

Output :

				
					'sqa.tools.python'

				
			

convert a string into a list of words.

count and display the vowels in a string

Convert a string into a list of words.

In this program, we will take a string as input and convert a string into a list of words.

Steps to solve the program
  1. Take a string as input.
  2. Convert the string into a list of words using split().
  3. Print the output.
				
					#Input string
string = "learning python is fun"
list1 = string.split(" ")

#Printing output
print(list1)
				
			

Output :

				
					['learning', 'python', 'is', 'fun']
				
			

check whether a string contains all letters of the alphabet or not.

swap commas and dots in a string.

String contains all letters alphabet or not.

In this program, we will take a string as input and string contains all letters alphabet or not

Steps to solve the program
  1. Take a string as input.
  2. Import string library and create a set of all alphabets using string library.
  3. Check whether a string contains all letters of the alphabet or not.
  4. Print True if yes else False.
				
					#Importing string
import string
alphabet = set(string.ascii_lowercase)

#Input string
string = "abcdgjksoug"

#Printing output
print(set(string.lower()) >= alphabet)
				
			

Output :

				
					False
				
			

strip spaces from a string.

convert a string into a list of words.

Strip spaces from a string.

In this program, we will take a string as input and strip spaces from a string.

Steps to solve the program
  1. Take a string as input.
  2. Strip the spaces from a string using strip().
  3. Print the output.
				
					#Input string
string = "    sqaltoolspythonfun     "

#Printing output
print(string.strip())
				
			

Output :

				
					sqaltoolspythonfun
				
			

print the index of the character in a string.

check whether a string contains all letters of the alphabet or not.