Show Menu
Cheatography

Lists - Python and Q Cheat Sheet (DRAFT) by

Python and Q equivalent of List operations

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Indexing

Function
Python
Q
by integer
l[2]
l[2]
first/last
 
first l
last l
from back
l[-2]
l[count[l] - 2
omiting brackets
 
l 2
by list
[l[i] for i in [2, 1]]
l[2 1]
multi-­dim­ens­ional
l[1][2]
l[1][2]
l[1; 2]
eliding index
 
l[; 1]
multi-­dim­ens­ional by list
 
l . 1 2
multi-­dim­ens­ional by list of lists
 
l ./: (1 2; 0 0)
 

Modifi­cation

Function
Python
Q
append single item
l.appe­nd(3)
l,: 3
append multiple items
l.exte­nd([5, 2])
l,: 5 2
append dictionary keys
l.exte­nd(d)
l,: key d
append dictionary values
l.exte­nd(­d.v­alu­es())
l,: d
insert
l.inse­rt(i, 7) 
l: (i#l), 7, i _ l
clear
l.clear()
l: 0#l
pop
l.pop()
l: -1 _ l
delete element
l.remo­ve(3)
l: l except 3
delete multiple element
[e for e in l1 if e not in l2]
l: l except l2
delete by index
del l[3]
l: l _ 3