python实现一个,其实就是所有的n位二进制位,n为字符串的长度,字符串较长时,结果数量2^n次可不是开玩笑的...- deb@BN067:~$ cat test.py
- #!/usr/bin/python3
-
- s="abcd"
-
- def bin2(i,n):
- return "{0:0{1}b}".format(i,n)
-
- def main():
- n=len(s)
- d=[{"0":i.lower(),"1":i.upper()} for i in s]
- for i in range(0,2**n):
- res="".join([d[j][k] for j,k in zip(range(0,n),bin2(i,n))])
- print(res)
-
- if __name__=="__main__":
- main()
- deb@BN067:~$ ./test.py
- abcd
- abcD
- abCd
- abCD
- aBcd
- aBcD
- aBCd
- aBCD
- Abcd
- AbcD
- AbCd
- AbCD
- ABcd
- ABcD
- ABCd
- ABCD
复制代码
|