itertools.islice - Deepstash

Explore the World's Best Ideas

Join today and uncover 100+ curated journeys from 50+ topics. Unlock access to our mobile app with extensive features.

itertools.islice

islice(iterable, stop)

islice(iterable, start, stop, [step])

  • Returns an iterator that produces the selected elements from the iterable. It skips start elements from the iterable, and then produces values until stop is reached, or until the iterator is exhausted. This affects execution speed when it needs to skip lots of elements.
  • It's memory efficient because it doesn't allocate extra memory for the iterated elements, and it can be used to slice both iterables and iterators. Standard indexing (a[start:stop]) doesn't work on iterators because they don't implement __getitem__().

2

7 reads

MORE IDEAS ON THIS

slice

slice

slice(stop)

slice(start, stop, [step])

  • Standard indexing relies on slice():Β a[start:stop:step]Β callsΒ a.__getitem__(slice(start, stop, step)).
  • slice() creates a shallow copy of the selected elements fro...

2

11 reads

slice or islice?

Choosing between slice() and islice() is a trade-off between memory usage and iteration speed. slice() is faster, but requires more memory, whereas islice() allocates a constan...

2

8 reads

CURATED FROM

CURATED BY

ocpodariu

Alt account of @ocp. I use it to stash ideas about software engineering

🐍 Python docs & Stack Overflow

β€œ

Read & Learn

20x Faster

without
deepstash

with
deepstash

with

deepstash

Access to 200,000+ ideas

β€”

Access to the mobile app

β€”

Unlimited idea saving & library

β€”

β€”

Unlimited history

β€”

β€”

Unlimited listening to ideas

β€”

β€”

Downloading & offline access

β€”

β€”

Personalized recommendations

β€”

β€”

Supercharge your mind with one idea per day

Enter your email and spend 1 minute every day to learn something new.

Email

I agree to receive email updates