slice or 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.

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 constant amount of memory, but is slower.

Use slice() when:

  • you need fast iteration speed, and you afford the extra memory usage

Use islice() when:

  • you need to slice iterators, or
  • memory efficiency is important to you

2

8 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

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, ...

2

7 reads

CURATED FROM

IDEAS CURATED BY

ocpodariu

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

🐍 Python docs & Stack Overflow

Other curated ideas on this topic:

5. Go slow

The slower you go the further you’ll get in your fitness journey. Fast results may be very tempting, but every shortcut comes at a price you won’t be willing to pay.

The faster your body changes, whether it is weight loss or muscle gain, the more o...

Study Less Study Smart

  1. Break your study time down in to chunks such as 30 minutes and then take a 5 minute break to keep your brain fresh and awake as you are studying.
  2. Teach what you learn to others. This is one of the big values from study groups.
  3. Know the difference between recollection and rec...

Things To Be Considered By Freelancers

Things To Be Considered By Freelancers

  • Finding New Work Every Now and Then: You need to make sure you are building good relations with potential clients, applying for jobs, answering emails, and constantly improving your work and marketing strategy.
  • Recurring Gigs: Having recurring gigs...

Read & Learn

20x Faster

without
deepstash

with
deepstash

with

deepstash

Personalized microlearning

100+ Learning Journeys

Access to 200,000+ ideas

Access to the mobile app

Unlimited idea saving

Unlimited history

Unlimited listening to ideas

Downloading & offline access

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