Python Ideas - Deepstash

python

21 ideas

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 from the original list.
  • Whenever you slice a list, the Python interpreter creates a new list and populates it with references to the elements you selected from the original list. Given that a reference needs 8 bytes on 64-bit systems,Β the overhead of copying references becomes noticeable when working with large lists. For example, slicing 1000 elements allocates almost 8kb worth of references.

2 STASHED

slice or islice? When to use which

🐍 Python docs & Stack Overflow

3 IDEAS

Returns an infinite iterator that produces evenly spaced values starting with number start.

It's often used in combination with map() to generate consecutive data points, and with zip() to add sequence numbers.

2 STASHED

Python's Infinite Count Generator

🐍 Exploring itertools docs

2 IDEAS

β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ
β€Œ

❀️ Brainstash Inc.