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')]
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 | Consecutive Maximum Occurrence in list
- Python - Maximum Consecutive Substring Occurrence
- Generate two output strings depending upon occurrence of character in input string in Python
- Python | Last occurrence of some element in a list
- Python | Replace multiple occurrence of character by single
- Python | First occurrence of True number
- Python | Count occurrence of all elements of list in a tuple
- Python | Percentage occurrence at index
- Python | Element Occurrence in dictionary of list values
- Python | Count tuples occurrence in list of tuples
- Python | Sort tuple based on occurrence of first element
- Python | Add the occurrence of each number as sublists
- Python program to find occurrence to each character in given string
- Python | Find last occurrence of substring
- Python | Get the string after occurrence of given substring
- Python | Split on last occurrence of delimiter
- Python | Ways to find nth occurrence of substring in a string
- Python | Split string on Kth Occurrence of Character
- Python | Check element for range occurrence
- Python | K occurrence element Test
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.