t434.py 668 B

123456789101112131415161718192021
  1. l = [0]*5
  2. l[1] = 1; print l[1] == 1
  3. l[2:5] = range(2,5); print l[2] == 2 and l[3]==3 and l[4] == 4
  4. del l[2:5]; print len(l)==2
  5. l = [0]*5
  6. l[0:5:2] = range(0,5,2); l[1:4:2] = range(1,4,2)
  7. print l == list(range(5))
  8. del l[0:5:2]; print l == [1,3]
  9. l.append(5); print l == [1,3,5]
  10. l.extend([7,9]); print l == [1,3,5,7,9]
  11. l.extend(l); print l == [1,3,5,7,9,1,3,5,7,9]
  12. print l.count(3) == 2
  13. print l.count(2) == 0
  14. print l.index(3) == 1
  15. print l.index(9) == 4
  16. l.pop(0); print l == [3,5,7,9,1,3,5,7,9]
  17. l.remove(3); print l == [5,7,9,1,3,5,7,9]
  18. l.reverse(); print l == [9,7,5,3,1,9,7,5]
  19. l.sort(); print l == [1,3,5,5,7,7,9,9]
  20. l.sort(lambda x,y: y-x); print l == [9,9,7,7,5,5,3,1]