Iterating over range(0,len(temp),-1) doesn't work
Question: I have the following code which does not enter the loop and I can't understand
why.

    
    
    python file.py 1111100000000
    

Code:

    
    
    import argparse
    
    p = argparse.ArgumentParser()
    p.add_argument("bits", help = "array_of_bits")
    args = p.parse_args()
    bits = args.bits
    
    temp = []
    
    for i in bits:
        temp.append([int(i)])
    
    print (temp)
    
    fin = []
    j = 0
    
    for i in range(0,len(temp),(-1)):
        if ( (temp[i] == 0) ):
            fin.extend(temp[j].append(temp[i]))
        if ( len(temp[i]) != 1 ):
            fin.extend(temp[j].append(temp[i]))
    
    j = j + 1
    
    print (fin)
    

What I wanted to get is:

    
    
    [[1], [1], [1], [1], [1], [0], [0], [0], [0], [0], [0], [0], [0]]
    [[10010], [10010], [100]
    

But instead I get this:

    
    
    [[1], [1], [1], [1], [1], [0], [0], [0], [0], [0], [0], [0], [0]]
    [[]]
    


Answer: The problem is the `range` you're iterating over in your `for` loop:

    
    
    for i in range(0,len(temp),(-1)):
    

`range(0,len(temp),(-1))` is an empty range, therefore the loop gets never
executed.

Your range would start with 0 and produce items smaller than `len(temp)`, but
in steps of `-1` i.e. counting downwards from 0. This way it could never ever
reach its target value, because `len` is always positive.

