gpt4 book ai didi

python - 删除位数组中前导 0 的索引

转载 作者:行者123 更新时间:2023-11-30 23:33:27 25 4
gpt4 key购买 nike

我正在尝试删除从列表中创建的位数组的前导 0。我想做的是:

while binPayload[0] == 0:
del binPayload[0]

但是中断器正在抛出:

IndexError: list assignment index out of range.

最佳答案

在索引之前,您应该每次检查列表是否为空。自 an empty list is considered false ,你可以简单地这样做:

while binPayload and binPayload[0] == 0:
del binPayload[0]

关于python - 删除位数组中前导 0 的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18797623/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com