## How do I split a list?

If you want to split the list into lists of equal size, see this related faq on the # (take) operator.

If you want to split a string on a delimiter, use the vs (vector from scalar) function:

q)” ” vs “The quick brown fox”
“The”
“quick”
“brown”
“fox”
q)”, ” vs “Hello, world!”
“Hello”
“world!”
q)

When its left argument is the null symbol, `, the vs function breaks apart a symbol on dots:

q)` vs `foo.bar.baz
`foo`bar`baz
q)

Those are the most common cases. We can also split a list into lists of varying length by passing a list of indexes as the left argument to the _ (cut) operator:

q)0 1 4 9 _ til 10
,0
1 2 3
4 5 6 7 8
,9
q)

To split a list of some type other than char using a delimiter is a little more complicated. We start by finding the indexes in the list that match the delimiter:

q)list: 1 2 0 3 4 0 5 6
q)delimiter: 0
q)indexes: where delimiter = list
q)indexes
2 5
q)

Now we can break list into pieces using the _ (cut) operator as above:

q)indexes _ list
0 3 4
0 5 6
q)

This is almost what we want. We’ll use _/: (drop-each-right) to get rid of the delimiters:

q)1 _/: indexes _ list
3 4
5 6
q)

We can grab the first element of the result with # (take):

q)first[indexes] # list
1 2
q)

Then we can just join (using ,) the two together:

q)(enlist first[indexes] # list), 1 _/: indexes _ list
1 2
3 4
5 6
q)

Note that we must call enlist on the front of the list or else we’ll get something a little different from what we intended:

q)(first[indexes] # list), 1 _/: indexes _ list
1
2
3 4
5 6
q)

Lastly, we can generalize to non-atomic types by replacing = with ~/: (match-each-right):

```split: {[list; delimiter]
indexes: where delimiter ~/: list;
front: first[indexes] # list;
rest: 1 _/: indexes _ list;
: (enlist front), rest;
}
```

## How do I remove a key from a dictionary?

Pass the key you want to remove as the left argument to the _ (drop) operator, and pass the dictionary as its right argument:

q)dict: `a`b`c ! 1 2 3
q)dict
a| 1
b| 2
c| 3
q)`b _ dict
a| 1
c| 3
q)

If you reverse the order of the arguments, the removal still works:

q)dict _ `b
a| 1
c| 3
q)

Although we can’t think of a good reason to do this, you might come across it. As our commenter Attila pointed out, however, you are more likely to see this overload in its assignment form:

q)dict _: `b / same as dict: dict _ `b
q)dict
a| 1
c| 3
q)

Meanwhile, you can remove multiple keys at once by passing a list of keys as the left argument to _ (drop):

q)`a`c _ dict
b| 2
q)

Reversing the arguments does not work in this case:

q)dict _ `a`c
‘type
q)

## How can I experiment on a production kdb while keeping the data free from accidental damage?

Use the -b command line argument to start kdb in read only mode, or start up with a negative port number.

one can verify the read-only mode by examining the return value of function \_

```\$ q -b
KDB+ 2.7 2011.02.16 Copyright (C) 1993-2011 Kx Systems
...
q)\_
1
q)
```