3

I am a beginner in python so this may seem easy to some people but I am stuck and don't know how to do this. What I want to do is to write a python code that takes a string like "abc" then it generates all possible combinations of the string based on capital and small letters without changing the sequence of the letters. for example if the input is abc the output should be: - abc - Abc - ABc - ABC - aBC - abC - AbC - aBc You might have noticed that number of the outputs will be 2^(number of alphabetic characters in the string)
Does any one have any idea how this can be done?

And further, solution should work correctly when the source string contains not only letters, but some special chars such as @ and . Because, for example, @ does not have lower case it will give me some duplicates in the output , how can I make it so only alphabetic characters are upper/lower ? for example if the input is a@c the output shoud only be : - A@c - a@C - A@C - a@c Thanks in advance!

VolAnd
  • 6,367
  • 3
  • 25
  • 43
user00239123
  • 270
  • 4
  • 16
  • If the letters upcase order is relevant in the output, the output differs from the suggested duplicate. – marcanuy Jul 15 '16 at 22:04
  • The upcase order is not important , thank you guys very much , I have got a working code now! – user00239123 Jul 15 '16 at 22:06
  • Alright , so the duplicate question does fix my problem , but if the string contains some special chars such as `@` and `.` , it will give me some duplicates in the output , how can I make it so only alphabetic characters are upper/lower ? for example if the input is a@c the output shoud only be : - `A@c` - `a@C` - `A@C` - `a@c` ? – user00239123 Jul 15 '16 at 22:14
  • @M.Gamal: you can put the `upper()` and `lower()` of each character into a `set` and pass the sets to `itertools.product`. This will eliminate the duplication for characters that don't have distinct cases. – Blckknght Jul 16 '16 at 05:07

0 Answers0