Skip to content

Instantly share code, notes, and snippets.

@arturoaviles
Created June 8, 2019 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arturoaviles/22eab0938898f31261ba74e778a346a4 to your computer and use it in GitHub Desktop.
Save arturoaviles/22eab0938898f31261ba74e778a346a4 to your computer and use it in GitHub Desktop.
Python Iteration starting at X index without copying the list
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