+3

What's wrong in this??

l=list(map(int,input().strip().split())) p=len(l) j=1 for i in range(0,p): if(j<p): if(l[i]==l[j]): print("hi") l.remove(l[i]) j=j+1

12/3/2019 7:10:15 PM

Pratik Kumbhar

5 Answers

New Answer

+2

https://code.sololearn.com/cxkqPzb8P3zo/?ref=app

+5

Pratik Kumbhar If the values in the list are same then your code will remove 1 element which will reduce the length of the list. But the for loop started with a fixed length of the list. As a result you will get "list index out of range exception" so say you have 100 100 4 5 length = 4 and valid index (0 to 3) when an element is removed say 100, then list length will become 3 and trying to access index 3 will cause an exception.

+1

i run the code with some input values, and it does work properly. What input value did cause your problem?

0

100 100 50 40....this cause error

0

https://code.sololearn.com/cQyWWfYI9nug/?ref=app