Skip to main content
4 of 8
added expected output

Equivalents permutations function

My function is supposed to essentially give the cartesian product of all the letters in a string with the caveat that you have to give the permutations of every equivalent of each character in a string (capital and lowercase for example). This is what I came up with but I believe it has a bike of something like k^n, k being the number of equivalents of each character.

import string
from pprint import pprint

equivs = {x[0]:x for x in list(zip(string.ascii_lowercase,string.ascii_uppercase))}

st = "missifsffs"


def perms(st):
    out = [""]
    for let in st:
        out = [y+x for y in out for x in equivs[let]]
    return out
print(perms("miss")) #['miss', 'misS', 'miSs', 'miSS', 'mIss', 'mIsS', 'mISs', 'mISS', 'Miss', 'MisS', 'MiSs', 'MiSS', 'MIss', 'MIsS', 'MISs', 'MISS']
print(perms("okay")) #['okay', 'okaY', 'okAy', 'okAY', 'oKay', 'oKaY', 'oKAy', 'oKAY', 'Okay', 'OkaY', 'OkAy', 'OkAY', 'OKay', 'OKaY', 'OKAy', 'OKAY']



print(perms(st))