Ad

Thursday, October 5, 2017

Python Interview List Slicing

a = [1,2,3,4] 
a[0:3] 
-> [1, 2, 3] 

 a[0:3:2] # slice with increment of 2 
->[1, 3] 

 a[::-1] # reverse slicing 
->[4, 3, 2, 1] 

 t=(1,2,3,4,5) #slicing tuples 
t[0:4] 
->(1, 2, 3, 4) 

 t=(1,2,3,4,5) 
sliceObj = slice(1,3) 
t[sliceObj] ->(2, 3)

No comments:

Post a Comment

MATLAB eBook on Machine Learning

Working on graduate study work? MATLAB now offers a free eBook on Machine Learning. Great resource for those in the academia. https://www....