Given a string ‘char_seq'(sequence of characters) and a positive integer ‘dig_seq'(sequence of digits), Write a Python program to find possible bijection or one-one onto relationship between ‘char_seq’ and ‘dig_seq’ such that each character matches to one and only one digit.
Input : char_seq = 'bxdyxb' dig_seq = 123421 Output : True Input : char_seq = 'bxdyxb' dig_seq = 123321 Output : False
Method #1 : Using zip method
This method simply zips the ‘char_seq’ and ‘dig_seq’ and checks if corresponding digits and characters matches or not.
Method #2 : Using itertools.groupby method
This method uses the same approach with a slight difference, it uses itertools.groupby to match characters with digits.
- Python | Ways to check string contain all same characters
- Check if both halves of the string have same set of characters in Python
- Python program to check if a string contains all unique characters
- Python Program for Check if all digits of a number divide it
- Python Program to check whether it is possible to make a divisible by 3 number using all digits in an array
- Python | Convert list of strings and characters to list of characters
- Check if the sum of digits of a number N divides it
- Check whether the sum of absolute difference of adjacent digits is Prime or not
- Second most repeated word in a sequence in Python
- Python - Odd Frequency Characters
- Possible Words using given characters in Python
- Python - Key with all Characters in String
- Python | Reverse sequence of strictly increasing integers in a list
- Iterate over characters of a string in Python
- Python | Replace multiple characters at once
- Python - Successive Characters Frequency
- Python | Extract only characters from given string
- Python - String with most unique characters
- Python | Consecutive characters frequency
- Python | Minimum Sum of Consecutive Characters
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.