2034 private links
I was asked on Twitter why Python uses 0-based indexing, with a link to a new (fascinating) post on the subject (http://exple.tive.org/blarg/2013/10/22/citation-needed/). I recall thinking about it a lot; ABC, one of Python's predecessors, used 1-based indexing, while C, the other big influence, used 0-based. My first few programming languages (Algol, Fortran, Pascal) used 1-based or variable-based. I think that one of the issues that helped me decide was slice notation.
Let's first look at use cases. Probably the most common use cases for slicing are "get the first n items" and "get the next n items starting at i" (the first is a special case of that for i == the first index). It would be nice if both of these could be expressed as without awkward +1 or -1 compensations.
Using 0-based indexing, half-open intervals, and suitable defaults (as Python ended up having), they are beautiful: a[:n] and a[i:i+n]; the former is long for a[0:n].
Using 1-based indexing, if you want a[:n] to mean the first n elements, you either have to use closed intervals or you can use a slice notation that uses start and length as the slice parameters. Using half-open intervals just isn't very elegant when combined with 1-based indexing. Using closed intervals, you'd have to write a[i:i+n-1] for the n items starting at i. So perhaps using the slice length would be more elegant with 1-based indexing? Then you could write a[i:n]. And this is in fact what ABC did -- it used a different notation so you could write a@i|n.(See http://homepages.cwi.nl/~steven/abc/qr.html#EXPRESSIONS.)
But how does the index:length convention work out for other use cases? TBH this is where my memory gets fuzzy, but I think I was swayed by the elegance of half-open intervals. Especially the invariant that when two slices are adjacent, the first slice's end index is the second slice's start index is just too beautiful to ignore. For example, suppose you split a string into three parts at indices i and j -- the parts would be a[:i], a[i:j], and a[j:].
So that's why Python uses 0-based indexing.
Oh que ça serait cool !
Borrowing from the technique used in the timeit module, loop with repeat() instead of range() to avoid unnecessary creation and destruction of integer objects. Gives a modest speed-up (in the 5% r...
A setup.py script using distutils / setuptools is the standard way to package Python code. Often, however, we need to perform custom actions for code generation, running tests, profiling, or building documentation, etc., and we’d like to integrate these actions into setup.py. In other words, we’d like...
mocha-style tests for python. Contribute to xi/assamtest development by creating an account on GitHub.
founder/Dir. of Engineering at Cuttlesoft, software engineer, CS researcher, brewer of coffee, drinker of teas, maker of faces. FSU '14.
Python implementation of the Rust dbg
macro.
En attendant f"{foo:d}" :)
Python Challenge home page,
The most entertaining way to explore Python. Every puzzle can be solved by
a bit of (python) programming.
Hunter is a flexible code tracing toolkit. . Contribute to ionelmc/python-hunter development by creating an account on GitHub.
FlashText is 28x faster than Complied Regex
A "Best of the Best Practices" (BOBP) guide to developing in Python. - bobp-python.md
+1000 !
Whatever your programs are doing, they often have to deal with vast amounts of
data. This data is usually represented and manipulated in the form of strings.
However, handling such a large quantity of input in strings can be very
ineffective once you start manipulating them by copying, slicing, and modifying.
Why?
Let's consider a small program which reads a large file of binary data, and
copies it partially into another file. To examine out the memory usage of this
program, we will use memory_
We found our hard to diagnose Python memory leak problem in numpy and numba using C/C++. It turned out that the numpy array resulting from the above operation was being passed to a numba generator compiled in "nopython" mode. This generator was not being iterated to completion, which caused the leak.
A new OS for connected devices. Create a greener, safer and faster interconnected world with SynapOS., the new opereating system for a new connected world.
(MicroPython)
I am a big fan of Dave Whyte’s vector animations, like this one: It was generated using a special animation language called Processing (here is Dave …
Un super article pour comprendre un peu plus Pandas et améliorer sa consommation mémoire.
via http://indexerror.net/5144/explosion-de-la-ram-en-utilisant-dataframe?show=5228#a5228
Ah c'est super cool ça !
Un gars a utilisait mon module Pythob MSS dans son application pour changer en temps réel la couleur des spots. Le rendu est terrible !
La description est :
Synchronise Philips Hue lights with computer display. Runs on Linux, Mac and Windows.