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)

t[:]
-> returns a full copy of the list

No comments:

Post a Comment

Applying for jobs at the Lending Club

We tried to figure out Lending Club 's tech stack for 2019. Our analysis shows Lending Club asks for skills in Python, Tableau, SQL and ...