Skip to main content
2 of 2
deleted 1644 characters in body
Sp3000
  • 62.3k
  • 13
  • 117
  • 292

Avoid list.insert

Instead of list.insert, appending to a slice is shorter:

L.insert(i,x) L[:i]+=x, 

For example:

>>> L = [1, 2, 3, 4] >>> L[:-2]+=5, >>> L [1, 2, 5, 3, 4] >>> L[:0]+=6, >>> L [6, 1, 2, 5, 3, 4] 
Sp3000
  • 62.3k
  • 13
  • 117
  • 292