python反向解析 reverse出现pop from empty list错误? Python 中reverse()问题

\u7b80\u5355Python\u7a0b\u5e8f\u51fa\u9519 IndexError: pop from empty list

>>> import random
>>> random.randint(1000,9999)

\u8fd9\u6837\u4e0d\u597d\u5417\u2026\u2026\u4f60\u8fd9\u4e2a\u5199\u7684\u548c\u9012\u5f52\u4e00\u6837\uff0c\u5f88\u96be\u7406\u89e3\u7684\u3002
\u62a5\u7684\u9519\u662f\u8bf4\u4f60array3\u91cc\u9762\u6ca1\u6709\u5143\u7d20\u4e86\uff0c\u90fd\u5220\u5b8c\u4e86\u3002

range\u7684\u53c2\u6570\u8981\u5199\u5bf9
>>> list(range(19,-1,-1))[19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]\u6392\u5e8f
>>> a=list(range(20))>>> a.sort(reverse=True)>>> a[19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]

答: 从提示pop from the empty list可以得知,在访问列表时出现了列表为空,然后还试图将其弹出的情况,你可以看看在你的代码中中,是不是有删除列表元素的操作,那么在删除之前可以先判断一下列表是否为空,为空的话,则不进行操作。希望可以帮助到你。



扩展阅读:python re sub ... python random sample ... python range 5 ... 乳腺癌erpr全是90% ... python randomrandint ... python re模块 ... python代码大全 ... 一张图看懂免疫组化 ... python random用法 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网