Python – Check if Elements delimited by K
Given a String, check if each segment is delimited by K.
Input : test_str = ’72!45!geeks!best’, K = ‘!’
Output : True
Explanation : All numerics and alphabets separated by delim border.
Input : test_str = ’72!45geeks!best’, K = ‘!’
Output : False
Explanation : No separation between 45 and geeks.
Method : Using isdigit() + isalpha() + loop
This is way in which this task can be performed. In this, we perform task of checking for alphabets and digits segments using isalpha() and isdigit(). Presence of any element, not entirely number or alphabet, is termed to non-delimited by K, and it remains unresolved during split().
The original string is : 72@45@geeks@best Are all delimited by K : True
Time Complexity: O(n)
Auxiliary Space: O(n)
My Personal Notes arrow_drop_up
Please Login to comment...