1

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

  • http://stackoverflow.com/questions/8537916/whats-the-idiomatic-syntax-for-prepending-to-a-short-python-list to prepend to a list. – Michael Hagar Jun 05 '14 at 14:11

1 Answers1

1

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])

coder006
  • 525
  • 1
  • 6
  • 15