Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

list inside list python

I am not looking to get an list inside list instead I just want to add zeros but do not know how. see code

def  myconv(x,h):
    q=[]
    print(h)
    for i in range(len_h):
        q.append(h[len_h-1-i])
    print(q)
    q.insert(0,([0]*len_h))       #I want this to add just plain zeros to the array... not an array insdie an
                                  #like it is doing here
    q.insert(len(q)+1,(0]*len_h))  

    print(q)

print(myconv([6,7,8,9],[1,2,3,4,5,6,7,8,9,0]))
like image 796
Tammy Logger Avatar asked Apr 17 '26 02:04

Tammy Logger


1 Answers

You want to use +, e.g. [0, 0, 0] + [2, 1, 3] == [0, 0, 0, 2, 1, 3], to concatenate an array onto the first. Otherwise, you'll need to insert (or append) items one at a time.

like image 152
Isaac Avatar answered Apr 18 '26 16:04

Isaac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!