Sometimes, while working with strings, we can have a problem in which we need to check the count of each character between the consecutive character. This type of problem can have application in day-day and web development domain. Lets discuss certain ways in which this task can be performed.
Method #1 : Using loop
This is brute force way in which this task can be performed. In this, we iterate the list counting the K character between each of characters.
The original string is : g...f..g.i..s....b..e....s...t List of character count : [3, 2, 1, 2, 4, 2, 4, 3]
Method #2 : Using list comprehension +
This is yet another way in which this problem can be solved. In this, we check for occurring K character using findall() and list comprehension is used to iterate about the string.
The original string is : g---f--g-i--s----b--e----s---t List of character count : [3, 2, 1, 2, 4, 2, 4, 3]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Pair the consecutive character strings in a list
- Python | Consecutive Character Maximum difference
- Python | Custom Consecutive Character Pairing
- Python - Custom Consecutive character repetition in String
- Python | Insert character after every character pair
- Python program to read character by character from a file
- Python - Create a Dictionary with Key as First Character and Value as Words Starting with that Character
- Python | Split string in groups of n consecutive characters
- Python | Minimum Sum of Consecutive Characters
- Python | Consecutive characters frequency
- Python - Consecutive Repetition of Characters
- Python - K length consecutive characters
- Python - Equidistant consecutive characters Strings
- Python | Replacing Nth occurrence of multiple characters in a String with the given character
- Python program to Replace all Characters of a List Except the given character
- Binary string with given frequencies of sums of consecutive pairs of characters
- Python | Convert list of strings and characters to list of characters
- Python program to print k characters then skip k characters in a string
- Find the first non-repeating character from a stream of characters
- Maximum length prefix such that frequency of each character is atmost number of characters with minimum frequency
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.