Arc Forumnew | comments | leaders | submitlogin
1 point by Pauan 4956 days ago | link | parent

"Would this be useful?"

It is in Python. Would it be useful in Arc? We already have cut, which does the same thing:

  (cut '(1 2 3 4) 0 2) -> (1 2)
But having a shorter syntax is nice. Would it be useful to assign to it? I think so, for the same reasons that it's nice in Python.


1 point by akkartik 4956 days ago | link

"It is [useful] in Python."

Python doesn't allow assigning to slices, I think.

-----

1 point by Pauan 4956 days ago | link

It absolutely does! It also allows for deleting indices/slices:

  foo = [1, 2, 3, 4]
  foo[0:2] = [0]
  foo -> [0, 3, 4]

  del foo[0:1]
  foo -> [3, 4]
In fact, there's an idiomatic way to delete every element in a list:

  del foo[:]
  foo -> []

-----

2 points by akkartik 4956 days ago | link

Ah.

And del is identical to assigning to [].

  >>> foo = [0, 1, 2]
  >>> foo[0:1] = []
  >>> foo
  [1, 2]
I stand corrected.

-----