diff options
author | Raymond Hettinger <python@rcn.com> | 2009-06-11 22:08:48 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2009-06-11 22:08:48 (GMT) |
commit | 75b544886bc43aa2aeb49522d9f640af116f97ab (patch) | |
tree | b1c97afc11883f9ffe2755b2538f10ba37c67d04 /Doc | |
parent | 16e527fc1aa4677dc1f6c2f6aabb2dadc4631f61 (diff) | |
download | cpython-75b544886bc43aa2aeb49522d9f640af116f97ab.zip cpython-75b544886bc43aa2aeb49522d9f640af116f97ab.tar.gz cpython-75b544886bc43aa2aeb49522d9f640af116f97ab.tar.bz2 |
Add example of how to do key lookups with bisect().
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/bisect.rst | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/Doc/library/bisect.rst b/Doc/library/bisect.rst index 9364ed8..eb32354 100644 --- a/Doc/library/bisect.rst +++ b/Doc/library/bisect.rst @@ -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)] |