-
-
Save IndhumathyChelliah/b2d9559073f64c06d2337ee8e5fe07e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
#if only one argument is mentioned other than iterable,it is stop value. | |
l1=itertools.islice([1,2,3,4,5,6,7,8,9,10],5) | |
print (list(l1))#Output:[1, 2, 3, 4, 5] | |
#start=2 and stop=5 mentioned. It will start from second index and ends at fifth index | |
l2=itertools.islice([1,2,3,4,5,6,7,8,9,10],2,5) | |
print (list(l2))#Output:[3,4,5] | |
#start=2,step=3.It will start from second index and increment by 3. | |
l3=itertools.islice([1,2,3,4,5,6,7,8,9,10],2,None,3) | |
print (list(l3))#Output:[3,6,9] | |
#step is given as negative value,it raises ValueError | |
l4=itertools.islice([1,2,3,4,5,6,7,8,9,10],2,None,-2) | |
print (list(l4))#Output:ValueError: Step for islice() must be a positive integer or None. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment