---
title: "bisect"
author: "vergilwang"
date: "2013-01-11T16:30:00Z"
tags: []
categories: ["编程语言"]
slug: "bisect"
draft: false
lastmod: "2014-02-15T15:43:42Z"
id: 2011282
url: "https://vergilwang.iteye.com/blog/2011282"
---

# from bisect import bisect\_left

a = \['liu', 'yuan', 'is', 'a', 'chinese']

bisect\_left(a, 'is')

此模块可以查找已知的element在序列中的index（从左向右找出第一个）

 

 

 

# Python Doc

 

[http://docs.python.org/release/2.5/lib/module-bisect.html](http://docs.python.org/release/2.5/lib/module-bisect.html)

 

&lt;nobr&gt;&lt;strong&gt;&lt;tt id="l2h-746" class="function" style="font-family:'lucida typewriter',lucidatypewriter,monospace"&gt;bisect\_left&lt;/tt&gt;&lt;/strong&gt;(&lt;/nobr&gt; `list, item`\[`, lo`\[`, hi`]``]``)

Locate the proper insertion point for`item`in`list`to maintain sorted order. The parameters`lo`and`hi`may be used to specify a subset of the list which should be considered; by default the entire list is used. If`item`is already present in`list`, the insertion point will be before (to the left of) any existing entries. The return value is suitable for use as the first parameter to`list.insert()`. This assumes that`list`is already sorted.New in version 2.1.