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.