设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
楼主: crossin先生
打印 上一主题 下一主题

集中答疑专用贴

  [复制链接]

0

主题

0

好友

8

积分

新手上路

Rank: 1

楼主
发表于 2014-11-30 18:17:08 |显示全部楼层
here is the code:

>>>x = [0,1,2,3,0,3,2,1,8]
>>> for i in range(0,len(x)):
            for j in range(i+1,len(x)):
                if x[i] == x[j]:
                        del x[j]



Traceback (most recent call last):
  File "<pyshell#181>", line 3, in <module>
    if x[i] == x[j]:
IndexError: list index out of range

实际上是每运行一次 都能去掉一个重复的数.. 为什么第二次会超出列表范围呢? 难道是del后,list没有能及时更新?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-5-3 17:32 , Processed in 0.027602 second(s), 22 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部