String that consists multi-time occurring chars

In this program, we will take a string as input and create a string that consists of multi-time occurring characters in the said string.

Steps to solve the problem
  1. Take a string as input.
  2. From collections import counter to count the occurrences of the characters in the given string.
  3. Print only those characters who have occurred more than once.
				
					#Input string
str1 = "aabbcceffgh"

#Importing counter
from collections import Counter   
str_char = Counter(str1)

part1 = [ key for (key,count) in str_char.items() if count>1] 

#printing output
print("Occurring more than once: ", "".join(part1))
				
			

Output :

				
					Occurring more than once:  abcf
				
			

remove all consecutive duplicates of a given string

create a string from two given strings combining uncommon characters of the said strings.  

Leave a Comment