Advertisement
rfmonk

operator_sequences.py

Jan 16th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. from operator import *
  5.  
  6. a = [1, 2, 3]
  7. b = ['a', 'b', 'c']
  8.  
  9. print 'a =', a
  10. print 'b =', b
  11.  
  12. print '\nConstructive:'
  13. print ' concat(a, b):', concat(a, b)
  14. print ' repeat(a, 3):', repeat(a, 3)
  15.  
  16. print '\nSearching:'
  17. print ' contains(a, 1)   :', contains(a, 1)
  18. print ' contains(b, "d") :', contains(b, "d")
  19. print ' countOf(a, 1)    :', countOf(a, 1)
  20. print ' countOf(b, "d")  :', countOf(b, "d")
  21. print ' indexOf(a, 5)    :', indexOf(a, 1)
  22.  
  23. print '\nAccess Items:'
  24. print ' getitem(b, 1)       :', getitem(b, 1)
  25. print ' getslice(a, 1, 3)   :', getslice(a, 1, 3)
  26. print ' setitem(b, 1, "d")  :', setitem(b, 1, "d"),
  27. print ', after b =', b
  28. print ' setslice(a, 1, 3, [4, 5]):', setslice(a, 1, 3, [4, 5]),
  29. print ', after a =', a
  30.  
  31. print '\nDestructive:'
  32. print ' delitem(b, 1)   :', delitem(b, 1), ', after b =', b
  33. print ' delslice(a, 1, 3):', delslice(a, 1, 3), ', after a =', a
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement