how to delete from a list?

hi,

?

I have an entry level question:

?

say you have a? list

temp:?abcdefgh

i have an index list

bad:2 3 4

?

does anyone know how to remove the indexs in bad from temp?

?

thanks!


CHEN, Cheng

this is one way, assuming bad is sorted:q)temp _/ bad+neg til count badOn Sun, Jul 17, 2011 at 12:39 PM, CHEN, Cheng wrote:> hi,>> I have an entry level question:>> say you have a? list> temp:?abcdefgh> i have an index list> bad:2 3 4>> does anyone know how to remove the indexs in bad from temp?>> thanks!>> –> CHEN, Cheng>> –>

Submitted via Google Groups

in place:

q).[`temp;();_/;bad+neg til count bad]

temp{x _ y}/bad

or

temp @ (til count temp) except bad

temp except temp[bad]On Jul 17, 7:39?pm, “CHEN, Cheng” <chench…> wrote:> hi,>> I have an entry level question:>> say you have a ?list> temp: abcdefgh> i have an index list> bad:2 3 4>> does anyone know how to remove the indexs in bad from temp?>> thanks!>> –> CHEN, Cheng</chench…>

unfortunately temp except temp[bad] doesn’t guarantee you won’t delete
elements you don’t want to delete.

temp{x _ y}/bad is not really what was asked as indexes will shift
while using over.

sorry about 1) , you are absolutely right :)

  1. should work for you though

a reliable and simple answer is: ?temp[(til count temp) except bad]

but: ?temp except temp bad ??is quicker if you have unique symbols

/ is overkill (bad joke)


q)temp:100000?`$/:.Q.a

q)bad:10000?til 100

q)\t do[100; temp _/ bad+neg til count bad]

252

q)\t do[100;?temp[(til count temp) except bad]]

55

q)\t do[100; temp except temp bad]

36

David.

Though, as walter says, in the special condition where bad is sorted, using over is slightly quicker:

q)bad:asc 10000?til 100

q)\t do[100; temp _/ bad+neg til count bad]

31

To: personal-kdbplus@googlegroups.comX-Mailer: Apple Mail (2.1084)> say you have a list> temp: abcdefgh> i have an index list> bad:2 3 4> > does anyone know how to remove the indexs in bad from temp?temp:temp til[count temp]except bad

q)temp:100000?`$/:.Q.a

q)bad:10000?til 100

q)\t do[100; temp _/ bad+neg til count bad]

1465

q)\t do[100; temp[(til count temp) except bad]]

113

q)\t do[100;{t:(count x)#1b;t[y]:0b;x where t}[temp;bad]]

44