def removeElement(A, elem): if not A: return 0 lis =  for item in A: if (item != elem): lis.append(item) A = lis #check what left in A #print A return len(A) print removeElement([4,5],4)
I got , 1 on my computer, but OJ think my output is  . I don't know how this happen.
I think the issue is not with the logic, but with extra space you used. In the question it was asked to do inplace, not using extra memory.
Give a try removing 'lis' and check.