Pyth reference and documentation
This file is intended to be read with line wrapping.
Tokens are given in the order: 1 character tokens, by code point, . tokens, by code point.
Types:
num = int, float
cmp = complex
seq = str, list, tuple
lst = list, tuple
idx = str, list, dict
col = str, list, set, dict
any = any expression (a for short)
blk = a code block (any series of statements)
... = any number of arguments of any type.
n:_ = n _ arguments.
var = variable. Not evaluated.
func = function. Not evaluated.
func n = function with arity n.
pfn = Preceding function of arity n. *F, for instance.
l:_ = Lambda with lambda variable(s) _
pos = positive int.
nneg = nonnegative int.
neg = negative int.
none = missing argument.
c/n or col/num = col or num, where num is cast to list using U.
s/n or seq/num = seq or num, where num is cast to list using U.
= Type1 whose elements are of the for Type2.
Shorthands:
In the text, A refers to the first argument, B to the second, etc.
If two type definitions overlap, more specific takes precedence.
No operations modify the input unless specifically specified.
x -> y -> z -> ... means on future / nested uses, the successive character is used. If there is an extra -> at the end, it is cyclic.
Format:
Char, Input types | Effect
Tokens:
0 Leading 0 is a separate token, number zero.
0123456789. Numeric literals. Leading 0 ignored, trailing . often parses separately
\n Print with trailing newline. Return input.
Identity function. Suppresses printing.
! Logical negation. 0, 0.0, "", [], (), {}, set() -> True, else False.
" Begin and end string literal.
# Loop until error statement. On error, suppress and break out of loop.
# Filter A(_, B ...) over C. Uses f underneath, B may refer to f's lambda var. # looks like a strainer.
$ Begin and end Python literal. Counts as one token. Disabled in -s (online).
% Modulo. Same as Python.
% Every Ath element of B. B[::A] in Python.
% Format string, B is list of arguments. % in Python.
% Format string, B is only argument.
% Apply modulo to real and imaginary parts separately.
& If not A, return A. Else, return B. Short-circuiting. Same as Python and.
' Open the file or website given by the input string. Return list of lines if normal file or website. Return list of color triples for color images, and list of brightness values for grayscale images.
( <...> Tuple constructor. tuple(A) in Python.
) End function or statement.
* Multiplication. * in Python.
* Repetition. * in Python.
* Repetition. * in Python.
* Cartesian product. All pairs of A_elem, B_elem.
+ Addition. + in Python.
+ Concatenate. + in Python.
+ Concatenate. + in Python (But cast to list).
+ Append B to the end of A.
+ Prepend A to the beginning of B.
+ Append str(B) to the end of A.
+ Prepend str(A) to the beginning of B.
+ Union of A and B.
+ Union of A and {B}.
, [A, B]
- Subtraction. - in Python.
- Filter A on absence from b. Uses not in.
- Cast A to B's type, then filter on absence.
- Cast B to A's type, then filter on absence.
/ Integer division. // in Python.
/ Count occurrences of B in A.
/ Count occurrences of B in A.
: Slice of A from B to C. A[B:C] in Python.
: Stepped range. Go from A to B with a step size of C.
: Multiple assignment. For i in B, A[i] = C[i], If C runs out, it repeats.
: Multiple assignment. For i in B, A[i] = C.
: Regex substitution. In A, replace B with C.
: 0| Regex search boolean. In A, return whether a match for B is found.
: 1 Regex search. In A, return every match for B (non overlapping)
: 2 In A, replace each match of regex B with its first capturing group.
: 3 Split A on matches of regex B. Retain capturing groups.
: 4 Return list of match and all capturing groups for each match of B in A.
; End all containing functions, statements, etc., if not inside a lambda function.
; Global value of innermost lambda's first variable.
< Less than, numeric.
< Less than, lexicographic.
< Less than, lexicographic.
< First B elements of A. A[:B] in Python.
< All but last A elements of B. B[:len(B)-A] in Python.
< Less than, absolute value/magnitude.
< Less than, absolute value/magnitude.
< Proper subset.
= ` Assign A value B. deepcopy value before assignment. Return assigned value.
= <...> Assign x value A(B,..), where x is the first variable after the =, or Q if there is none. The Python Y += 3 would be =+Y3. Return assigned value.
> Greater than, numeric.
> Greater than, lexicographic.
> Greater than, lexicographic.
> A at and after index B. A[B:] in Python.
> Last A elements of B. B[len(B)-A:] in Python.
> Greater than, absolute value/magnitude.
> Greater than, absolute value/magnitude.
> Proper superset.
? Ternary. A ? B : C in C-like languages. B if A else C in Python.
@ Index into the sequence. Modular wrapping. A[B % len(A)] in Python.
@ Index into the dict. A[B] in Python.
@ Intersection. Filter B on presence in A.
@ Root. A ** (1/B) in Python.
A ` Assign the first value of the list to G and the second to H. Return the input.
B Break. Ends surrounding statement.
B Bifurcate. Return two element list [B, A(B, ...)].
C Character with code point A. If A is too large, convert to base 256 and turn each into a character.
C C(floor(A))
C Complex conjugate.
C Convert A to int using base 256 and code points.
C Matrix transpose, truncating to the length of the shortest entry.
D Define a function. Same as def A(B...) in Python.
D Sort operator. Sort C with key A(_, B ...). Uses o underneath, B may refer to o's lambda var.
E Evaluate input. Same as ast.literal_eval(input()) in Python.
F Apply repeatedly. A(A(A(A(... B ... )))), C times.
F Fold A over B, with first element as initial value. Same as .U bZ **. On empty sequence, value is 0, unless A is *, in which case it is 1.
F Apply A to B, with splatting. A(*B) in Python.
F **` For A in range(int(B)): C
F `` For A in B: C
G Variable. Initialized to "abcdefghijklmnopqrstuvwxyz", alphabet.
H Variable. Initialized to {}. (Hash table)
I if A: B
I Invariant. A(B, ...) == B.
J Variable, Autoinitializing. J=A on first use and all uses before an assignment expression finishes.
J Variable. After the assignment expression.
K Variable, Autoinitializing. K=A on first use and all uses before an assignment expression finishes.
K Variable. After the assignment expression.
L def y(b): return A. y -> ' ->
L Left map. n>=2. Map A(B, ..., _) over C, where _ is the lambda variable. Map uses m underneath, and B may refer to its lambda variable.
M def g(G,H): return A. g -> n ->
M Map. Map A(_) over B, where _ is the lambda variable. Map uses m underneath.
M Map. Map A(*_) over B, where _ is the lambda variable. Map uses m underneath. Each element of B is splatted as the arguments to A.
N Variable. Initialized to '"', quote mark.
O If A > 0, random int below A. If A == 0, random float 0 to 1. If A < 0, random.seed(-A).
O Random float 0 to A.
O A multiplied by random float 0 to 1.
O Random element of A.
P List of prime factors of A with multiplicity in increasing order. Uses sympy if sympy is installed, trial division otherwise. Empty list if A is 0 or 1.
P Returns whether -A is prime.
P Complex phase of A.
P All but the last element of A. A[:-1] in Python.
Q Variable, Autoinitialized to eval(input()).
R Return, used inside D.
R Right map. n >= 2. Map A(_, B, ...) over C, where _ is the lambda variable. Map uses m underneath, and B may refer to its lambda variable.
S Sort. sorted(A) in Python.
S 1-indexed range. [1, 2, ... A].
S 1-indexed range up to floor of A.
T Variable. Initialized to 10. (Ten)
U Unary range. [0, 1, ... A-1]. range(A) in Python.
U Reversed unary range. [A, A+1, ... -1]. range(A, 0) in Python.
U Unary range of length. [0, 1, ... len(A)-1]. range(len(A)) in Python.
V Shorthand for 'FNU'. N -> H -> b ->
V Shorthand for 'FN'. N -> H -> b ->
V Vectorized function. Equivalent to MC,
W While loop. while A: B in Python.
W `** Conditional application. If B, A(C, ...). Else, C.
X ** Dictionary assignment. A[tuple(B)] = C in Python.
X Dictionary assignment. A[B] = C
X String assignment. Replace in A at index B with str(C). Modular indexing.
X Sequence assignment. Replace in A at index B with C. Modular indexing.
X Translate A from B to C. Modular indexing.
X Translate A from B to B[::-1].
X In-place +=. B[A] += C. Modular indexing. Uses Pyth +.
X B[tuple(A)] += C, or B[tuple(A)] = C if tuple(A) not in B. Uses Pyth +.
X B[A] += C, or B[A] = C if A not in B. Uses Pyth +.
X Insert into string. Insert str(C) into B at A.
Y Variable. Initialized to [], empty list.
Z Variable. Initialized to 0. (zero)
[ <...> List constructor, unbounded number of arguments. [A1, A2, A3, A4 ... ], where A1, A2, .. are the arguments. Often used with ")".
\ One character string.
] [A].
^ Exponentiation. A ** B in Python.
^ Repeated Cartesian Product. itertools.product(A, repeat=B) in Python.
_ Negation. -A in Python.
_ Reversal. A[::-1] in Python.
_ Swap keys and values.
` Representation. repr in Python.
a Append. A.append(B) in Python. Return A.
a Add. A.add(B) in Python. Return A.
a Absolute difference. abs(A - B) in Python.
b Variable. Initialized to '\n', newline.
c Float division. A / B in Python.
c Split. A.split(B) in Python.
c Split on whitespace. A.split() in Python.
c Chop A into pieces of length B. Last shorter if necessary.
c Chop A into B pieces of equal sizes, initial pieces one longer if necessary.
c Chop A at every location in B.
c Chop A at every occurrence of B.
d Variable. Initialized to ' ', space.
e End. A[-1] in Python.
e Imaginary part. A.imag in Python.
e Last digit. A % 10 in Python.
f Filter A(_) over B. T -> Y -> Z ->
f First input where A(_) is truthy over [B, B+1, B+2, ...]
f First input where A(_) is truthy over [1, 2, 3, 4...]
g Greater than or equal. A >= B in Python.
g Greater than or equal. A >= B in Python.
g Superset. A.issuperset(B)
g Inclusive slice. A[B-1:] in Python.
h Head. A[0] in Python.
h A + 1.
i Convert A from base B to int. if A is '', return 0. int(A, B) in Python.
i Convert A from base B to int.
i GCD.
j Convert A to base B as a list.
j Join B on A. Convert elements of B to strings if needed.
j Join A on newlines.
j Join B on A. Convert A to a string, elements of B to strings.
k Variable. Initialized to '', empty string.
l len(A).
l log base 2 of A.
m Map A(_) over B. d -> k -> b ->
n A != B
o Sort B with key function A. sorted(B, key=A) in Python. N -> Y ->
p Print A, with no trailing newline. Return A.
q A == B
r 0 A.lower()
r 1 A.upper()
r 2 A.swapcase()
r 3 A.title()
r 4 A.capitalize()
r 5 string.capwords(A)
r 6 A.strip() - Remove whitespace on both sides of A.
r 7 Split A, eval each part.
r 8 Run length encode A. Output format [[3, 'a'], [2, 'b'], [1, 'c'], [1, 'd']].
r 9 Run length decode A. Input format '3a2bcd' -> 'aaabbcd'
r 9 Run length decode A. Input format [[3, 'a'], [2, 'b'], [1, 'c'], [1, 'd']].
r Range, half inclusive. range(A, B) in Python, or range(A, B, -1).
r String range. r(C(A), C(B)), then convert each int to string using C.
r r(B, A)
s Concatenate. ''.join(A)
s reduce on +, base case []. (Pyth +)
s Real part. A.real in Python.
s Floor to int. int(A) in Python.
s Parse as int. "" parses to 0. int(A) in Python.
t