0001 # 0002 # Example of using Python lists 0003 # 0004 box = [ 'pencil', 'pen', 'ruler', 'eraser' ] 0005 print box 0006 #['pencil', 'pen', 'ruler', 'eraser'] 0007 # 0008 for item in box: print item, 0009 print 0010 # pencil pen ruler eraser 0011 # 0012 box.reverse() 0013 for item in box: print item, 0014 print 0015 # eraser ruler pen pencil 0016 # 0017 box.sort() 0018 for item in box: print item, 0019 print 0020 # eraser pen pencil ruler 0021 # 0022 for i in range(0, len(box)): print box[i], 0023 print 0024 # eraser pen pencil ruler 0025 # 0026 for i in range(len(box)-1, -1, -1): print box[i], 0027 print 0028 # ruler pencil pen eraser 0029 # 0030 for i in range(-1, -len(box)-1, -1): print box[i], 0031 print 0032 # ruler pencil pen eraser 0033 # 0034 bag = [ 'data structures', 'calculus', box, 2012012012 ] 0035 print bag 0036 # ['data structures', 'calculus', ['eraser', 'pen', 'pencil', 'ruler'], 2012012012] 0037 for item in bag: print item, 0038 print 0039 # data structures calculus ['eraser', 'pen', 'pencil', 'ruler'] 2012012012 0040 for item in bag[2]: print item, 0041 print 0042 # eraser pen pencil ruler 0043 for item in bag[2][1:3]: print item, 0044 print 0045 # pen pencil