0
    import itertools
    import string

    def crackdict(max, min=1, chars=None):
 assert max >= min >= 1

 if chars is None:
  import string
  chars = string.printable[:-5]

 p = []
 for i in xrange(min, max + 1):
  p.append(itertools.product(string.printable[:-5], repeat=i))

 return itertools.chain(*p)

    #Just for test:
    max, min = 4, 1
    d = crackdict(max, min)

i want to print the result like this 0 1 2 3 4 5 6

but now the print like [('0',), ('1',), ('2',), ('3',), ('4',), ('5',), ('6',), ('7',), ('8',), ('9',), ('a',), ('b',), ('c',), ('d',), ('e',), ('f',), ('g',), ('h',), ('i',), ('j',), ('k',), ('l',), ('m',), ('n',), ('o',), ('p',), ('q',), ('r',), ('s',), ('t',), ('u',), ('v',), ('w',), ('x',), ('y',), ('z',), ('A',), ('B',), ('C',), ('D',), ('E',), ('F',), ('G',), ('H',), ('I',), ('J',), ('K',), ('L',), ('M',), ('N',), ('O',), ('P',), ('Q',), ('R',), ('S',), ('T',), ('U',), ('V',), ('W',), ('X',), ('Y',), ('Z',), ('!',), ('"',), ('#',), ('$',), ('%',), ('&',), ("'",), ('(',), (')',), ('*',), ('+',), (',',), ('-',), ('.',), ('/',), (':',), (';',), ('<',), ('=',), ('>',), ('?',), ('@',), ('[',), ('\',), (']',), ('^',), ('_',), ('`',), ('{',), ('|',), ('}',), ('~',), (' ',), ('0', '0'), ('0', '1'), ('0', '2'), ('0', '3'), ('0', '4'), ('0', '5'), ('0', '6'), ('0', '7'), ('0', '8'), ('0', '9'), ('0', 'a'), ('0', 'b'), ('0', 'c'), ('0', 'd'), ('0', 'e'), ('0', 'f'), ('0', 'g'), ('0', 'h'), ('0', 'i'), ('0', 'j'), ('0', 'k'), ('0', 'l'), ('0', 'm'), ('0', 'n'), ('0', 'o'), ('0', 'p'), ('0', 'q'), ('0', 'r'), ('0', 's'), ('0', 't'), ('0', 'u'), ('0', 'v'), ('0', 'w'), ('0', 'x'), ('0', 'y'), ('0', 'z'), ('0', 'A'), ('0', 'B'), ('0', 'C'), ('0', 'D'), ('0', 'E'), ('0', 'F'), ('0', 'G'), ('0', 'H'), ('0', 'I'), ('0', 'J'), ('0',

how can i do it ? thanks!

2
  • 2
    How is ('1', '2', '3') similar in any way to "aaaaaa"? Do you think you could make your example consistent with itself? Commented Jul 7, 2010 at 0:51
  • i want to the list translate to string like this ('1','2','3') 123 Commented Jul 7, 2010 at 1:12

3 Answers 3

5
>>> ''.join(['a', 'b', 'c'])
'abc'
>>>
Sign up to request clarification or add additional context in comments.

Comments

0

How about:

return [''.join(itertools.product(chars, repeat=i)) for i in xrange(min, max + 1)]

instead of everything in the function starting from p = [].

Comments

0

You can use "delimiter".join(list)

a_list = ["Hello", "Stack", "Overflow"]
a_str = " ".join(a_list)    # " " is the delimiter
b_str = "-".join(a_list)    # "-" is the delimiter
c_str = "".join(a_list)     # ""  is the delimiter
print(a_str)
print(b_str)
print(c_str)

Output :

Hello Stack Overflow

Hello-Stack-Overflow

HelloStackOverflow

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.