Sometimes, while working with Strings, we can have a problem in which we need to check whether we can find occurrence of characters consecutive and according to English alphabets. This kind of problem can occur in school programming and day-day programming. Lets discuss certain ways in which this task can be performed.
Method #1 : Using loop +
ascii_letters + zip()
The combination of above methods can be used to perform this task. In this, we extract the English alphabets using ascii_letters and check for consecution using zip().
The original string is : geeksforgeeks is best fgr geeks
The Consecutive matching letter pairs : [(‘f’, ‘g’), (‘s’, ‘t’)]
Method #2 : Using list comprehension +
ascii_letters + zip()
The combination of above methods can be used to perform this task. In this, we perform similar way as above just in one-liner shortened way using list comprehension.
The original string is : geeksforgeeks is best fgr geeks The Consecutive matching letter pairs : [('f', 'g'), ('s', 't')]
- Python - Maximum Consecutive Substring Occurrence
- Python | Consecutive Maximum Occurrence in list
- Python - Slice from Last Occurrence of K
- Python | K occurrence element Test
- Python | First occurrence of True number
- Python | Percentage occurrence at index
- Python | Add the occurrence of each number as sublists
- Python | Substitute character with its occurrence
- Python | Split on last occurrence of delimiter
- Python - Substitute K for first occurrence of elements
- Python | Get the string after occurrence of given substring
- Python | Find last occurrence of substring
- Python - Remove first occurrence of K in Tuple
- Python | Last occurrence of some element in a list
- Python - Sum of each List element occurrence in another
- Python program to remove Nth occurrence of the given word
- Python | Check element for range occurrence
- Python - Occurrence counter in List of Records
- Python | Split string on Kth Occurrence of Character
- Python - Replace duplicate Occurrence in String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.