简体   繁体   English

如何通过索引从J中的列表中删除元素?

[英]How to remove an element from a list in J by index?

The rather verbose fork I came up with is 我想出的相当冗长的分叉是

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

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? 在J中这样做的常用方法是什么?

Yes, the J-way is to use a 3-level boxing: 是的,J-way是使用3级拳击:

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

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

It's a small note in the dictionary for { : 这是{字典中的一个小注释: {

Note that the result in the very last dyadic example, that is, (<<<_1){m , is all except the last item. 请注意,最后一个二元示例中的结果,即(<<< _ 1){m,除了最后一项之外的所有结果。

and a bit more in Learning J: Chapter 6 - Indexing: 6.2.5 Excluding Things . 学习J中的更多内容:第6章 - 索引:6.2.5排除事物

Another approach is to use the monadic and dyadic forms of # (Tally and Copy). 另一种方法是使用# (Tally和Copy)的monadic和二元形式。 This idiom of using Copy to remove an item is something that I use frequently. 这种使用Copy来删除项目的习惯用法是我经常使用的。

The hook (ii@#) uses Tally (monadic #) and monadic and dyadic i. 钩子(ii@#)使用Tally(monadic#)和monadic和dyadic i. (Integers and Index of) to generate the filter string: (整数和索引)生成过滤字符串:

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

which Copy (dyadic #) uses to omit the appropriate item. Copy(dyadic#)用于省略相应的项目。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM