cancel
Showing results for 
Search instead for 
Did you mean: 

how to delete from a list?

Felix
New Contributor
hi,
I have an entry level question:
say you have a� list
temp:�`a`b`c`d`e`f`g`h
i have an index list
bad:2 3 4
does anyone know how to remove the indexs in bad from temp?
thanks!

--
CHEN, Cheng

10 REPLIES 10

wp
New Contributor
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:�`a`b`c`d`e`f`g`h> i have an index list> bad:2 3 4>> does anyone know how to remove the indexs in bad from temp?>> thanks!>> --> CHEN, Cheng>> --> You received this message because you are subscribed to the Google Groups> "Kdb+ Personal Developers" group.> To post to this group, send email to personal-kdbplus@googlegroups.com.> To unsubscribe from this group, send email to> personal-kdbplus+unsubscribe@googlegroups.com.> For more options, visit this group at> http://groups.google.com/group/personal-kdbplus?hl=en.>

wp
New Contributor


in place:

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

_Oz_
New Contributor

temp{x _ y}/bad

or

temp @ (til count temp) except bad

Daniel
New Contributor
temp except temp[bad]On Jul 17, 7:39�pm, "CHEN, Cheng" wrote:> hi,>> I have an entry level question:>> say you have a �list> temp: `a`b`c`d`e`f`g`h> i have an index list> bad:2 3 4>> does anyone know how to remove the indexs in bad from temp?>> thanks!>> --> CHEN, Cheng

wp
New Contributor


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.

_Oz_
New Contributor
sorry about 1) , you are absolutely right 🙂
2) 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

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

Aaron_Davies
New Contributor
To: personal-kdbplus@googlegroups.comX-Mailer: Apple Mail (2.1084)> say you have a list> temp: `a`b`c`d`e`f`g`h> 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