From: Raymond Hettinger Date: Thu, 11 Jun 2009 22:08:48 +0000 (+0000) Subject: Add example of how to do key lookups with bisect(). X-Git-Tag: v2.6.3rc1~202 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=75b544886bc43aa2aeb49522d9f640af116f97ab;p=python Add example of how to do key lookups with bisect(). --- diff --git a/Doc/library/bisect.rst b/Doc/library/bisect.rst index 9364ed8287..eb32354bd3 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)]