Use of islice()


Just wondering if there is a specific reason that the islice() function is being used, in PySpark?

Instead of the following where LST is a list

LST = [1,2,3,4,5,6,7,8,9,10]
import itertools
for i in itertools.islice(LST,0,5): print i

the following is better and simple, and would return the same result set. Isn’t it right?

LST = [1,2,3,4,5,6,7,8,9,10]
print LST[0:5]

Yes, it is correct. I just came to know about the later syntax recently.