python -> combinations of numbers and letters

前端 未结 4 815
醉话见心
醉话见心 2020-12-18 17:36
#!/usr/bin/python
import random
lower_a = [\'a\', \'b\', \'c\', \'d\', \'e\', \'f\', \'g\', \'h\', \'i\', \'j\', \'k\', \'l\', \'m\', \'n\', \'o\', \'p\', \'q\', \'r         


        
4条回答
  •  一个人的身影
    2020-12-18 17:51

    I haven't tested this, but I think the basic idea should hold. Please comment if it doesn't work and I'll debug it:

    L = ['ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz', '0123456789']
    def f(L, length, s=''):
        print s
        if len(s) == length:
            print s
        else:
            for word in L:
                for char in word:
                    w = word.replace(char, '')
                    l = L[:]
                    l.remove(word)
                    l.append(w)
                    f(l, length, s+char)
    

提交回复
热议问题