w3resource

Python: Find all lower and upper mixed case combinations of a given string

Python Itertools: Exercise-41 with Solution

Write a Python program to find all lower and upper mixed case combinations of a given string.

Sample Solution:

Python Code:

import itertools
def combination(str1):
    result = map(''.join, itertools.product(*((c.lower(), c.upper()) for c in str1)))
    return list(result)
st ="abc"
print("Original string:")
print(st)
print("All lower and upper mixed case combinations of the said string:")
print(combination(st))
st ="w3r"
print("\nOriginal string:")
print(st)
print("All lower and upper mixed case combinations of the said string:")
print(combination(st))
st ="Python"
print("\nOriginal string:")
print(st)
print("All lower and upper mixed case combinations of the said string:")
print(combination(st))

Sample Output:

Original string:
abc
All lower and upper mixed case combinations of the said string:
['abc', 'abC', 'aBc', 'aBC', 'Abc', 'AbC', 'ABc', 'ABC']

Original string:
w3r
All lower and upper mixed case combinations of the said string:
['w3r', 'w3R', 'w3r', 'w3R', 'W3r', 'W3R', 'W3r', 'W3R']

Original string:
Python
All lower and upper mixed case combinations of the said string:
['python', 'pythoN', 'pythOn', 'pythON', 'pytHon', 'pytHoN', 'pytHOn', 'pytHON', 'pyThon', 'pyThoN', 'pyThOn', 'pyThON', 'pyTHon', 'pyTHoN', 'pyTHOn', 'pyTHON', 'pYthon', 'pYthoN', 'pYthOn', 'pYthON', 'pYtHon', 'pYtHoN', 'pYtHOn', 'pYtHON', 'pYThon', 'pYThoN', 'pYThOn', 'pYThON', 'pYTHon', 'pYTHoN', 'pYTHOn', 'pYTHON', 'Python', 'PythoN', 'PythOn', 'PythON', 'PytHon', 'PytHoN', 'PytHOn', 'PytHON', 'PyThon', 'PyThoN', 'PyThOn', 'PyThON', 'PyTHon', 'PyTHoN', 'PyTHOn', 'PyTHON', 'PYthon', 'PYthoN', 'PYthOn', 'PYthON', 'PYtHon', 'PYtHoN', 'PYtHOn', 'PYtHON', 'PYThon', 'PYThoN', 'PYThOn', 'PYThON', 'PYTHon', 'PYTHoN', 'PYTHOn', 'PYTHON']

Python Code Editor:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Python program to split a given list into specified sized chunks using itertools module.

Next: Write a Python program to create group of similar items of a given list.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/itertools/python-itertools-exercise-41.php