浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

sdict - sorted dictionary for python - Google Project Hosting

sdict is a module implementing python's build-in dict interface, and it supports range search and prefix matching. sdict it is an extension written in c.

Setup

  1. svn checkout http://sdict.googlecode.com/svn/trunk/ sdict
  2. cd sdict
  3. python setup.py install

 

(if you want to use sdict in the current directory, please use 'python setup.py build_ext --inplace' in the third step)

 

Usage Example

import sdict
d
= sdict.Dict()
d
['123']='haha value'
print d['123']

d
['a/b/c']='xxxxx'
d
['a/b/zz']='yyyy'
d
['a/zz']='zzzzz'
print 'prefix a:',d.prefix('a/')
print 'all keys:',d.keys()
print 'all values:',d.values()
print 'length:',len(d)
print 'd =',d

x
= sdict.Dict()
for i in xrange(100):
    x
[i] = i+1
del x[33]

print 'keys greater or equal to 33', x.greater(33)
print 'keys less than or equal to 32,at most 5 listed',x.less(32,limit=5)

print 'length:',len(x) 
posted on 2012-03-28 20:45  lexus  阅读(106)  评论(0)    收藏  举报