python二进制比较大小的方法_二进制字符串比较

我想把我最初的尝试作为第一个答案,但网站封锁了我大约8个小时,我现在只能回复。我把代码分成了更重要的片段。在

这是我目前为止的尝试:

我想我应该对下面的代码执行以下修改:1) Use dicts so that I have 0:000,1:001,... to improve the indexing.

2) Take the comparison string, adapt it to a list of all possible options

then compare this to the full binary list e.g. 010 becomes 110,000,011

and this is then is compared to the full binary list.

我尝试创建一个二进制数的列表如下(还没有使用dicts)

^{pr2}$

然后运行for循环,将每个字符串与其他字符串(当前不是最佳字符串)进行比较def GreySets(Bins):

for Bin1 in Bins :

for Bin2 in Bins :

stringXOR(Bin1,Bin2)

我从互联网上的其他人那里得到的字符串XOR,它返回一个truefalse true(我需要它来重新运行不匹配的位数)def stringXOR(a, b):

# Error Checking

msg = "Strings do not have same length: %d, %d!"

assert len(a) == len(b), msg % (len(a), len(b))

cnt = len(a) - 1

# Code

result = ''

while cnt + 1:

result = `(a[cnt] != b[cnt])` + result

cnt = cnt - 1

return result

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值