Remove punctuations from a string

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

Steps to solve the program
  1. Take a string as input.
  2. Create an empty string and a string containing all the punctuations.
  3. Use for loop to iterate over every character from the input string.
  4. If the character is not in the list containing punctuations then add that character to the empty string.
  5. Print the output.
				
					#Input string
string1 = "Sqatools : is best, for python"
string2 = ""
punc = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''

for char in string1:
    if char not in punc:
        string2 += char
        
#Printing output
print(string2)
				
			

Output :

				
					Sqatools  is best for python
				
			

remove empty spaces from a list of strings.

find duplicate characters in a string

Remove empty spaces from a list of strings.

In this program, we will take a list of strings as input and remove empty spaces from a list of strings.

Steps to solve the program
  1. Take a list of strings as input.
  2. Create an empty list.
  3. Add every string from the input list to the empty list except empty spaces.
  4. Print the output.
				
					#Input lists
List1 =  ["Python", " ", " ","sqatools"]
List2 = []

for string in List1:
    if string != " ":
        List2.append(string)

#Printing output
print(List2)
				
			

Output :

				
					['Python', 'sqatools']
				
			

replace different characters in the string at once.

remove punctuations from a string

Replace different characters in string at once.

In this program, we will take a string as input and replace different characters in string at once.

Steps to solve the program
  1. Take a string as input and create an empty string.
  2. Add each character from the given string to the empty string after replacing different characters.
  3. Use for loop for this purpose.
  4. Print the output.
				
					#Input string
string = "Sqatool python"
new_str = ""

for char in string:
    if char == "a":
        new_str += "1"
    elif char == "t":
        new_str += "2"
    elif char == "o":
        new_str += "3"
    else:
        new_str += char

#Printing output
print(new_str)
				
			

Output :

				
					Sq1233l py2h3n
				
			

replace multiple words with certain words.

remove empty spaces from a list of strings.

Replace multiple words with certain words.

In this program, we will take a string as input and replace multiple words with certain words.

Steps to solve the program
  1. Take a string as input.
  2. Convert the string of words into a list of words using split().
  3. Use for loop with range() function to iterate over each word in the list.
  4. Replace the word in the string with a defined word.
  5. Convert the list into a string using join().
  6. Print the output.
				
					#Input string
string = "I’m learning python at Sqatools"
List = string.split(" ")

for i in range(len(List)):
    if List[i] == "python":
        List[i] = "SQA"
    elif List[i] == "Sqatools":
        List[i] = "TOOLS"

#Printing output        
print(" ".join(List))
				
			

Output :

				
					I’m learning SQA at TOOLS
				
			

split strings on vowels

replace different characters in the string at once.

Split strings on vowels

In this program, we will take a string as input and split strings on vowels.

Steps to solve the program
  1. Take a string as input and import re library.
  2. Split the string on vowels using re.split().
  3. Print the output.
				
					#Importing re library
import re

#Input string
string = "qwerty"

#Splitting string on vowels
result = re.split('a|e|i|o|u', string)

#Printing output
print(" ".join(result))
				
			

Output :

				
					qw rty
				
			

print the mirror image of the string.

replace multiple words with certain words.

Print the mirror image of string.

In this program, we will take a string as input and print the mirror image of string.

Steps to solve the program
  1. Take a string as input.
  2. Print the mirror image of the string by reversing it.
  3. Use Indexing for this purpose.
				
					#Input string
string = "Python"

#Printing output
print(string[::-1])
				
			

Output :

				
					'nohtyP'
				
			

get a string made of the first 2 and the last 2 characters

split strings on vowels

Get a string made of the first and last 2 chars

In this program, we will take a string as input and get a string made of the first and last 2 chars

Steps to solve the program
  1. Take a list as input.
  2. Print the new string made of the first and last 2 characters from the given string using Indexing.
				
					#Input string
string = "Sqatools"

#Printing output
print(string[:2]+string[-2:])
				
			

Output :

				
					Sqls
				
			

get the first 4 characters of a string.

print the mirror image of the string.

Get the first 4 characters of a string

In this program, we will take a string as input and get the first 4 characters of a string.

Steps to solve the program
  1. Take a string as input.
  2. Print the first 4 characters of a string using Indexing.
				
					#Input string
string = "Sqatools"

#Printing output
print(string[:4])
				
			

Output :

				
					Sqat
				
			

words greater than the given length.

get a string made of the first 2 and the last 2 characters

Find the words greater than the given length.

In this program, we will take a string as input and find words greater than the given length.

Steps to solve the program
  1. Take a string as input.
  2. Split the given string using split().
  3. Find the words having lengths greater than 3 from the splitter string using For loop.
  4. Print the output.
				
					#Input string
string = "We are learning python"

for word in string.split(" "):
    if len(word) > 3:
        print(word,end=" ")
				
			

Output :

				
					learning python
				
			

find the least frequent character in a string.

get the first 4 characters of a string.

Repeat vowels and consonants 3 and 2 times resp.

In this program, we will take a string as input and repeat vowels and consonants 3 and 2 times respectively.

Steps to solve the program
  1. Take a string as input.
  2. Create an empty string and a list containing all the vowels.
  3. Using for loop check whether a character from the input string is a vowel or consonant.
  4. If it is a vowel then add it to the empty list 3 times each.
  5. If it is a consonant add it to the empty list 2 times each.
  6. Print the output
				
					#Input string
str1  = "Sqa Tools Learning"
result = ""
vowels = ["a","e","i","o","u",
          "A","E","I","O","U"]

for char in str1:
    if char in vowels:
        result = result + char*3
    else:
        result = result + char*2

#Printing output
print(result)
				
			

Output :

				
					SSqqaaa  TToooooollss  LLeeeaaarrnniiinngg
				
			

count vowels from each word in the given string show as dictionary

re-arrange the string.