Hello,

pls can anybody help me to break following string?

example:

output is 000 (type str) an I need to get [0,0,0]

here is a script:

def test(n_input):
    bin_n=2
    r=bin_n**n_input
##    print r

    for x in range(r):
##        print bin(x)
        f=str(bin(x))[2:].zfill(n_input) # x is type int, f is type str
        print type(f)

result is:
000
001
010
011
100
101
110
111

With list as I posted earlier:

def test(n_input):
    for x in range(2**n_input):
        f=str(bin(x))[2:].zfill(n_input) # x is type int, f is type str
        print list(f)

test(3)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.