How Do List To String In Python
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]
Solution 1:
>>>''.join(['a', 'b', 'c'])
'abc'
>>>
Solution 2:
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 = []
.
Solution 3:
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 delimiterprint(a_str)
print(b_str)
print(c_str)
Output :
Hello Stack Overflow
Hello-Stack-Overflow
HelloStackOverflow
Post a Comment for "How Do List To String In Python"