How to remove an item from a list in J by index?

A pretty detailed fork I came across

({. , (>:@[ }. ])) 

eg.

 3 ({. , (>:@[ }. ])) 0 1 2 3 4 5 0 1 2 4 5 

Works great, but is there a more idiomatic way? What is the usual way to do this in J?

+6
source share
2 answers

Yes, J-way should use 3-level boxing:

 (<<<5) { i.10 0 1 2 3 4 6 7 8 9 (<<<1 3) { i.10 0 2 4 5 6 7 8 9 

This is a short note in the dictionary for { :

Note that the result is in the most recent binary example, i.e. (<<_1) {m, is everything but the last element.

and a bit more in Learning J: Chapter 6 - Indexing: 6.2.5 Excluding Things .

+4
source

Another approach is to use monadic and dyadic forms # (Tally and Copy). This idiom of using Copy to delete an item is what I often use.

The quest (i. i.@ #) uses Tally (monadi #) and monadic and binary i. (Integers and Indexes) to create a filter string:

  2 (i. i.@ #) 'abcde' 1 1 0 1 1 

which uses Copy (dyadi #) to omit the corresponding element.

  2 ((i. i.@ #) # ]) 0 1 2 3 4 5 0 1 3 4 5 2 ((i. i.@ #) # ]) 'abcde' abde 
+3
source

Source: https://habr.com/ru/post/987630/


All Articles