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

Popular posts from this blog

css - I want to align grid in center -

Contact Form PHP Email Script -

python - SWIG function not printing output -