Formats a number, array, or dictionary using delimiter as the element separator.
Arithmetic
round(v, [nd])
Rounds v to nd decimal places. If the second argument is not specified, it rounds up to an integer.
floor(v)
Rounds the argument down to an integer.
ceil(v)
Rounds the argument up to an integer.
abs(v)
Returns the absolute value
min(a, b, ...)
Returns the minimum argument.
max(a, b, ...)
Returns the maximum argument.
rand()
Returns a fractional number in the half-interval [0, 1).
rand(a, b)
Returns an integer in the interval [a, b].
rand(arr)
Returns a random array element.
Working with strings
startswith(container, s)
Checks that the string container starts with the substring s.
endswith(container, s)
Checks that the string container ends with the substring s.
lower(s)
Converts a string to lower case. Convenient for later comparison with another string, case insensitive.
upper(s)
Converts a string to upper case.
strip(s)
Removes extra spaces at the beginning and end of a string.
split(s, [[sep=' ', [max_split=-1]])
Converts a string to an array, splitting it at the specified sep character (default is a space), you can also specify max_split - the maximum number of divisions.
replace(s, old, new, [count=-1])
Replaces the substring old in the string s with the string new. By default (if count is not specified) all occurrences of the substring are replaced.
Regular Expressions
Regular expressions allow you to check if a string matches a specified pattern, or to search for a substring by a pattern in another string. This is a rather complicated, but very powerful mechanism.
Finds a substring in the string s that matches the regular expression pattern. If there is no such substring, None is returned.
Supported flags:
i - case insensitive
m - multiline matching
s - . (dot) matches line breaks
match_groups(s, pattern, [flags])
Finds a substring in the string s that matches the regular expression pattern. If there is no such substring, None is returned.
Unlike match() returns not a substring, but an array of groups. Moreover, the first element of the array is the entire found substring.
Supported flags:
i - case insensitive
m - multiline matching
s - . (dot) matches line breaks
match_all(s, pattern, [flags])
Finds in the string s all substrings matching the regular expression pattern.
Supported flags:
i - case insensitive
m - multiline matching
s - . (dot) matches line breaks
Working with arrays
Operators
Slices
push(arr, v)
Adds the element v to the end of the arr array.
pop(arr, [i])
Removes the element at index i. If i is not specified, then the last element of the array is removed.
insert(arr, i, v)
Inserts the value v in place of i.
remove(arr, v)
Removes the first occurrence of the element with value v.
sorted(arr)
Returns a copy of the array, the values in which are sorted in ascending order.
sorted(arr, key, reversed=False)
Returns a copy of the array in ascending order (or descending if reversed is True). key is a function that returns a value by which to sort.
reversed(arr)
Returns a copy of an array whose values are in reverse order.
enumerate(arr)
Returns an array of (index, value) pairs.
shuffle(arr)
Returns a copy of the array sorted randomly.
index_of(arr, value)
Returns the index of the first array element equal to the specified value. If there is no element with the specified value in the array, None is returned.
join(arr, [sep])
Concatenates the elements of an array into a single string using the sep separator.
sum(arr)
Returns the sum of the array elements.
map(arr, l)
Returns a copy of the array resulting from applying the lambda function l to each of its elements.
filter(arr, l)
Returns a copy of an array whose elements match the filter specified by the l lambda function.
reduce(arr, l)
Combines the elements of an array into a single entity by calling the passed lambda function l on each element. The first argument of the lambda function is the result accumulated at the moment, the second is the next element of the array.
Working with dictionaries
Operators
get(k, [default])
Returns the value given by the key k. If there is no such key in the dictionary, default is returned.
keys(d)
Returns an array of dictionary keys.
values(d)
Returns an array of dictionary values.
map(d, l)
Returns the array resulting from applying the lambda function l to each key-value pair (k, v).
sorted(d, key, reversed=False)
Returns a copy of the dictionary in ascending order (or descending if reversed is True). key is a function that returns a value by which to sort.
>>> 'hello world' | match(r'world')
world
>>> 'hello world' | match(r'test')
None
# search for a number in a string
>>> 'top up, 500' | match(r'\d+')
500
# extract email from string
>>> 'My email: [email protected]' | match(r'\S+@\S+')
[email protected]# search case sensitive (default)
>>> 'TEST' | match(r'test')
None
# case insensitive
>>> 'TEST' | match(r'test', 'i')
TEST
# ^$ means the entire string must match the filter
>>> 'top up, 500' | match(r'^refill, \d+$')
replenish, 500
# extra text does not match the filter
>>> 'fill up, 500 some extra text' | match(r'^refill, \d+$')
None
# select 2 groups: number and currency
>>> 'top up with 100 rubles' | match_groups(r'(\d+) (\w+)')
['100 rubles', '100', 'rubles']
# find all numbers in a string
>>> '1, 2, 3, 4, 5' | match_all(r'\d+')
['1', '2', '3', '4', '5']
>>> arr = [1, 2, 3]
# get value by index
>>> arr[0]
one
# the last element of the array can be obtained like this:
>>> arr[-1]
3
# check if the value is in the array
>>> 3 in arr
True
# check for the absence of a value in the array
>>> 4 not in arr
True
# change value by index
>>> arr[0] = 100
>>> arr
[100, 2, 3]
# delete value by index
>>> del arr[0]
>>> arr
[2, 3]
>>> arr = [1, 2, 3, 4, 5]
# array elements starting at the specified index
>>> arr[2:]
[3, 4, 5]
# array elements up to the specified index
>>> arr[:2]
[12]
# every second element of the array
>>> arr[::2]
[1, 3, 5]
# flip the array
>>> arr[::-1]
[5, 4, 3, 2, 1]
# multiply each element by 2
>>> [1, 2, 3] | map(v => v * 2)
[2, 4, 6]
# filter out values greater than 5
>>> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | filter(v => v > 5)
[6, 7, 8, 9, 10]
# sum value
>>> [1, 2, 3] | reduce((acc, v) => acc + v)
6
# product value
>>> [1, 2, 3] | reduce((acc, v) => acc * v)
6
# sum of rows
>>> [1, 2, 3] | reduce((acc, v) => str(acc) + v)
123
# dictionary declaration
>>> cart = {'bread': 3, 'buckwheat': 10}
# get value by key
>>> basket['bread']
3
# check if the key exists in the dictionary
>>> 'bread' in basket
True
# change value by key
>>> basket['bread'] = 2
>>> shopping cart
{'bread': 2, 'buckwheat': 10}
# delete value by index
>>> del basket['buckwheat']
>>> shopping cart
{'bread': 2}