当前位置: 首页>>代码示例>>Python>>正文


Python SortedDict.bisect方法代码示例

本文整理汇总了Python中sortedcontainers.SortedDict.bisect方法的典型用法代码示例。如果您正苦于以下问题:Python SortedDict.bisect方法的具体用法?Python SortedDict.bisect怎么用?Python SortedDict.bisect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sortedcontainers.SortedDict的用法示例。


在下文中一共展示了SortedDict.bisect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_bisect_key

# 需要导入模块: from sortedcontainers import SortedDict [as 别名]
# 或者: from sortedcontainers.SortedDict import bisect [as 别名]
def test_bisect_key():
    temp = SortedDict(modulo, 7, ((val, val) for val in range(100)))
    assert all(temp.bisect(val) == ((val % 10) + 1) * 10 for val in range(100))
    assert all(temp.bisect_right(val) == ((val % 10) + 1) * 10 for val in range(100))
    assert all(temp.bisect_left(val) == (val % 10) * 10 for val in range(100))
开发者ID:Milstein,项目名称:sorted_containers,代码行数:7,代码来源:test_coverage_sorteddict.py

示例2: test_bisect

# 需要导入模块: from sortedcontainers import SortedDict [as 别名]
# 或者: from sortedcontainers.SortedDict import bisect [as 别名]
def test_bisect():
    mapping = [(val, pos) for pos, val in enumerate(string.ascii_lowercase)]
    temp = SortedDict(mapping)
    assert temp.bisect_left('a') == 0
    assert temp.bisect_right('f') == 6
    assert temp.bisect('f') == 6
开发者ID:danbornside,项目名称:sorted_containers,代码行数:8,代码来源:test_coverage_sorteddict.py

示例3: isPhoto

# 需要导入模块: from sortedcontainers import SortedDict [as 别名]
# 或者: from sortedcontainers.SortedDict import bisect [as 别名]
# iterate through whole directory
for subdir, dirs, files in os.walk(photosDirectory) :
  for file in files :

    if isPhoto(file) :
      try :
        exif = getExif(os.path.join(subdir, file))
        if not cameraIsValid(exif) :
          continue
        # get focal length and convert from rational data type to float
        focalLength = exif[FOCALLENGTH_TAG][0] / exif[FOCALLENGTH_TAG][1]
        # count every focal length occurence in dictionary
        if (focalLength in occurences) :
          occurences[focalLength] = occurences[focalLength] + 1
        else:   # find nearest
          index = occurences.bisect(focalLength)
          greater = occurences.iloc[index]
          smaller = occurences.iloc[index - 1]
          nearestFL = greater if (greater - focalLength < focalLength - smaller) else smaller
          occurences[nearestFL] = occurences[nearestFL] + 1
      except (KeyError, TypeError, IndexError) :
        # there is no focal length info in image exif data (Key/Type/IndexError)
        pass

# plot the graph
position = arange(len(focalLengths)) + .5
barh(position, occurences.values(), align='center', color='#FF0000')
yticks(position, occurences.keys())
xlabel('Occurrences')
ylabel('Focal length')
title('Focal length usage analysis')
开发者ID:mc-suchecki,项目名称:etc,代码行数:33,代码来源:flanalyzer.py


注:本文中的sortedcontainers.SortedDict.bisect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。