join - Python : Generate a string of bits. -
i trying generate random string of bits using following code.
bitstring = [] in range(0, 8): x = str(random.randint(0, 1)) bitstring.append(x) ''.join(bitstring)
however instead of giving me this:
10011110
i looks this:
['1','0','0','1','1','1','1','0']
can point me in direction of i'm doing wrong?
thanks!
bitlist = [] in range(0, 8): x = str(random.randint(0, 1)) bitlist.append(x) bitstring = ''.join(bitlist)
more pythonic this:
>>> random import choice >>> ''.join(choice(['0', '1']) _ in xrange(10)) '0011010100'
Comments
Post a Comment