Skip to content

flip

Transpose

flip x     flip[x]

Returns x transposed, where x is a list of lists, a dictionary, or a simple table.

In a list of lists, each list must be the same length; otherwise flip signals a length error.

q)flip (1 2 3;4 5 6)
1 4
2 5
3 6
q)flip (1 2 3;4 5)
'length
  [0]  flip (1 2 3;4 5)
       ^

The flip of a dictionary is a table, and vice versa. If x is a dictionary whose keys are symbols and whose values are lists of the same count (or atoms), flip x returns a table.

q)D:`sym`price`size!(`IBM`MSFT;10.2 23.45;100 100)
q)flip D
sym  price size
---------------
IBM  10.2  100
MSFT 23.45 100
q)D~flip flip D
1b

flip extends atoms to match the length of the lists. At least one item must be a list.

q)flip (1 2 3;4)
1 4
2 4
3 4
q)flip `sym`price`size!(`I;10.2 23.45 45.67;100)
sym price size
--------------
I   10.2  100
I   23.45 100
I   45.67 100
q)flip `a`b!(1;2)
'rank
  [0]  flip `a`b!(1;2)
       ^

You can't flip a keyed table: flip signals nyi.

q)flip ([k:1 2]v:3 4)
'nyi
  [0]  flip ([k:1 2]v:3 4)
       ^

! Flip Splayed or Partitioned, Dictionaries and tables