waving android

I am currently a software engineer at Google, where as a member of the Android platform team I build frameworks and user interfaces.

The blog here at is mostly historical; you can find more recent posts on .

Python slicing weirdity

October 17th, 2004


Huh?

>>> a=range(10)
>>> a
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> a[None] = 20
Traceback (most recent call last):
   File “<stdin>”, line 1, in ?
TypeError: list indices must be integers
>>> a[None:None] = [20]
>>> a
[20]

Yes, I actually ran into this, because I mistakenly inserted a value
into a list by slicing it with the result of insort_right()
(which returns None) when I clearly meant to call
bisect_right() (which returns an index into the list).

newer: older: