Created
June 8, 2019 20:38
-
-
Save arturoaviles/22eab0938898f31261ba74e778a346a4 to your computer and use it in GitHub Desktop.
Python Iteration starting at X index without copying the list
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
fruits = ["apple", "orange", "banana"] | |
# Simple Method (Inefficient). | |
for fruit in fruits[1:]: | |
print(fruit) | |
# Efficient Method (It doesn't needs to copy each element of the list). | |
from itertools import islice | |
for fruit in islice(fruits, 1, None): | |
print(fruit) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment