]> granicus.if.org Git - python/commitdiff
Add example of how to do key lookups with bisect().
authorRaymond Hettinger <python@rcn.com>
Thu, 11 Jun 2009 22:08:48 +0000 (22:08 +0000)
committerRaymond Hettinger <python@rcn.com>
Thu, 11 Jun 2009 22:08:48 +0000 (22:08 +0000)
Doc/library/bisect.rst

index 9364ed82877d692081a8ef122f7b1a328f40d9fd..eb32354bd3167f30ff3f668d8a94773f159ec33a 100644 (file)
@@ -94,8 +94,8 @@ Instead, it is better to search a list of precomputed keys to find the index
 of the record in question::
 
     >>> data = [('red', 5), ('blue', 1), ('yellow', 8), ('black', 0)]
-    >>> data.sort(key=lambda r: r[1])       # precomputed list of keys
-    >>> keys = [r[1] for r in data]
+    >>> data.sort(key=lambda r: r[1])
+    >>> keys = [r[1] for r in data]         # precomputed list of keys
     >>> data[bisect_left(keys, 0)]
     ('black', 0)
     >>> data[bisect_left(keys, 1)]