本文整理汇总了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))
示例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
示例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')