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

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

android - IBM Worklight 6.1 [Application Error] There was a network error (file:///android_asset/www/index.html) -