user3699095
user3699095

Reputation:

inserting a value in a 2d list - python 2.7

i have a list....

lst = [[45], [78], [264], [74], [67], [4756], [455], [465], [4567], [4566]]

and i want to add a zero at the beginning so it looks like this....

lst = [[0], [45], [78], [264], [74], [67], [4756], [455], [465], [4567], [4566]]

This doesn't work...

lst[0] = [0]

or This...

lst.append(0,[0])

what will actually work?

cheers

Upvotes: 1

Views: 2126

Answers (1)

coder006
coder006

Reputation: 525

As the name goes, append always adds at the end. You need to do this:

lst.insert(0, [0])

in stead of lst.append(0,[0])

Upvotes: 1

Related Questions