0

Is it possible to use python's slicing to get all but some item of a given array?

meaning, for example,

arr = range(10)
print(slicing_magic(arr, 4))

would output

[0 1 2 3 5 6 7 8 9]

I realize this could be done with

def slicing_magic(arr, ind):
    return arr[0:ind] + arr[ind+1:]

I wonder if there is a way without list addition, or

what is the most pythonic way?

Gulzar
  • 23,452
  • 27
  • 113
  • 201
  • @Aran-Fey not a duplicate.. I stated the obvious answer and that I am searching for a prettier one – Gulzar Mar 16 '19 at 21:25
  • All the sensible ways to do it are there. If you can't find anything "prettier", that's because nothing exists. – Aran-Fey Mar 16 '19 at 21:26

1 Answers1

0

You could do this?

def magic_slicer(arr, idx):
    b = arr.copy()
    del b[idx]
    return b