我有以下功能解决类型错误在Python/IPython的
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: unsupported operand type(s) for >>: 'float' and 'int'
注: 这个Python库仅在2.7和我支持使用2to3才能使用它。图书馆的其他部分按照需要工作,所以我一般有信心2to3工作。
我想在IPython 3.5中运行这个,我听说这样的一些错误可能发生在IPython中,所以我想知道它是否与此有关。
我用10101测试了代码,它工作正常。问题的输入是什么? –
@MHornbacher位= 31 –
我的结果:Windows 10 1607 python 2.7.3和Python 3.6.0你的代码在3秒内没有返回错误 –