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
- Possible Words using given characters in Python
- Python | Reverse sequence of strictly increasing integers in a list
- Python | Extract only characters from given string
- Python | Replace multiple characters at once
- Iterate over characters of a string in Python
- Ways to print escape characters in Python