【发布时间】:2017-04-19 03:41:59
【问题描述】:
我在使用以下功能时遇到问题
def get_lexographically_next_bit_sequence(self, bits):
"""
Bit hack from here:
http://www-graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation
Generator even does this in poker order rank
so no need to sort when done! Perfect.
"""
t = (bits | (bits - 1)) + 1
next = t | ((((t & -t) // (bits & -bits)) >> 1) - 1)
yield next
while True:
t = (next | (next - 1)) + 1
next = t | ((((t & -t) // (next & -next)) >> 1) - 1)
yield next
这个函数返回错误:
TypeError: >>: 'float' 和 'int' 的操作数类型不受支持
注意事项: 这个 python 库仅在 2.7 中受支持,我使用 2to3 来使用它。库的其他部分按需要工作,所以我通常相信 2to3 工作。
我正在尝试在 IPython 3.5 中运行它,我听说像这样的一些错误可能在 IPython 中特别发生,所以我想知道它是否与此有关。
【问题讨论】:
-
我用 10101 测试了代码,它运行良好。有问题的输入是什么?
-
@MHornbacher bits=31
-
我的结果:Windows 10 1607 python 2.7.3 和 Python 3.6.0 你的代码在 3 秒内没有返回错误
标签: python python-3.x python-2to3