Tutorials/Lists/Solutions

From Kx Wiki
Jump to: navigation, search

1. For example

q)myname:"abigail"
q)last myname
"l"
q)-1#myname
,"l"

2. Copy the list into your q process...

q)t?`o
4

q)where t=`o
4 17 19

q)t>`j			/ compare to return a boolean list
00011010111000110101b
q)sum t>`j		/ sum to get the total
10i
q)t where t>`j		/ return the values themselves
`n`o`k`l`m`m`m`m`o`o

3. Create your own mixed list and check that its type is 0h.

q)d:("h";`p;1;2h;0b)
q)type d
0h
q)i:45 39 81i
q)s:`this`is`a`list
q)m:i,s
q)n:(i;s)
q)n
45 39 81i
`this`is`a`list

4. Get the first element of each element using "first"

q)first each mylist
"h"
"w"
1
1b  

Get the first element of each element using indexing.

Note: Although we can specify every index in the top level, if an indexing level is omitted, every element is returned.\

q)mylist[0 1 2 3;0]	/ specifying every index
"h"
"w"
1
1b
q)mylist[;0]		/ omitting the first level
"h"
"w"
1
1b

Back to Tutorials

Personal tools
Namespaces
Variants
Actions
Navigation
Print/export
Toolbox