0

I am trying to remove a digit from an integer.

My code seems to work except when I input an integer such as 8880888.

For some reason, with an integer above, when removing the index passing the middle number, but it doesn't remove the correct index.

    n = 8880888
    def question(n):
        newlist = [int(x) for x in str(n)] #coverting integer to list
        result = newlist[:]
        y = newlist[5]
        result.remove(y)
    return result

When removing the 5th element, it should return 888088. But instead, I am being returned 880888.

Łukasz D. Tulikowski
  • 1,440
  • 1
  • 17
  • 36
Roozilla
  • 83
  • 9

1 Answers1

0

You are using remove() instead of a del method. If you are looking to remove an element based on an index, your code should look something like:

n = [8, 8, 8, 0, 8, 8, 8]

#If you want to remove the 5th element:

del n[5]

Please refer to https://www.csestack.org/difference-between-remove-del-pop-python-list/

Srini
  • 187
  • 1
  • 2
  • 13