Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

LOL

lol_add_column

Help on function lol_add_column in module pydicts.lol:

lol_add_column(rows, index, column)
    Adds a new column to a list of lists (LoL) at a specified index.

    Args:
        rows (list): The original list of lists.
        index (int): The index at which to insert the new column.
        column (list): A list of values representing the new column.
                       Its length must match the number of rows in `rows`.

    Returns:
        list: A new list of lists with the added column.

lol_add_row

Help on function lol_add_row in module pydicts.lol:

lol_add_row(lol_, index, row)
    Adds a new row to a list of lists (LoL) at a specified index.

    Args:
        lol_ (list): The original list of lists.
        index (int): The index at which to insert the new row.
        row (list): The new row to add. Its length must match the length of existing rows.

    Returns:
        list: The modified list of lists with the added row.

    Raises:
        exceptions.LolException: If the new row's size is different from existing rows.

from pydicts import lol
lol_=[[1, 2, 3], [4, 5, 6]]
lol_=lol.lol_add_row(lol_, 1, [2,3,5])
lol.lol_print(lol_)
+---+---+---+
| 1 | 2 | 3 |
| 2 | 3 | 5 |
| 4 | 5 | 6 |
+---+---+---+

lol_order_by

Help on function lol_order_by in module pydicts.lol:

lol_order_by(lol_, index, reverse=False, none_at_top=True)
    Orders a list of lists (LoL) by the value at a specified column index.

    Args:
        lol_ (list): The list of lists to sort.
        index (int): The column index to sort by.
        reverse (bool, optional): If True, sort in descending order. Defaults to False.
        none_at_top (bool, optional): If True, None values are placed at the beginning of the list.
                                      If False, None values are placed at the end. Defaults to True.

    Returns:
        list: The sorted list of lists.

from pydicts import lol
lol_=[[1, 2, 3], [4, 5, 6], [None, 4, None]]
lol_=lol.lol_order_by(lol_, 2, reverse=True, none_at_top=False)
lol.lol_print(lol_)
+---+---+---+
| 4 | 5 | 6 |
| 1 | 2 | 3 |
|   | 4 |   |
+---+---+---+

lol_print

Help on function lol_print in module pydicts.lol:

lol_print(lol_, number=None, align=None)
    Prints a list of lists (LoL) in a tabular format using the `tabulate` module.

    Args:
        lol_ (list): The list of lists to print.
        number (int, optional): The maximum number of rows to print. If None, all rows are printed.
                                Defaults to None.
        align (list, optional): A list of strings specifying column alignment. Possible values are
                                "right", "center", "left", "decimal", or None. Defaults to None.

from pydicts import lol
lol_=[[1, 22, 3], [41, 5, 6000]]
lol.lol_print(lol_, align=['left', 'right', 'center'])
+----+----+------+
| 1  | 22 |  3   |
| 41 |  5 | 6000 |
+----+----+------+

list_remove_positions

Help on function list_remove_positions in module pydicts.lol:

list_remove_positions(l, listindex)
    Removes elements from a list at specified indices.

    Args:
        l (list): The original list.
        listindex (list): A list of integer indices to remove.

    Returns:
        list: A new list with elements at the specified indices removed.

lol_remove_columns

Help on function lol_remove_columns in module pydicts.lol:

lol_remove_columns(rows, list_of_indexes)
    Removes specified columns from a list of lists (LoL).

    Args:
        rows (list): The original list of lists.
        list_of_indexes (list): A list of integer indices of columns to remove.

    Returns:
        list: A new list of lists with the specified columns removed.

lol_remove_rows

Help on function lol_remove_rows in module pydicts.lol:

lol_remove_rows(rows, listindex)
    Removes specified rows from a list of lists (LoL).

    Args:
        rows (list): The original list of lists.
        listindex (list): A list of integer indices of rows to remove.

    Returns:
        list: A new list of lists with the specified rows removed.

lol_transposed

Help on function lol_transposed in module pydicts.lol:

lol_transposed(lol)
    Transposes a list of lists (LoL), swapping rows and columns.

    Args:
        lol (list): The original list of lists.

    Returns:
        list: A new list of lists representing the transposed data.

    Raises:
        exceptions.LolException: If the input `lol` is None.

from pydicts.lol import lol_transposed
lol_=[[1, 2, 3], [4, 5, 6]]
lol.lol_print(lol_)
transposed=lol.lol_transposed(lol_)
lol.lol_print(transposed)
+---+---+---+
| 1 | 2 | 3 |
| 4 | 5 | 6 |
+---+---+---+
+---+---+
| 1 | 4 |
| 2 | 5 |
| 3 | 6 |
+---+---+

lol_get_column

Help on function lol_get_column in module pydicts.lol:

lol_get_column(lol, column)
    Extracts a specific column from a list of lists (LoL).

    Args:
        lol (list): The list of lists.
        column (int): The index of the column to extract.

    Returns:
        list: A list containing all values from the specified column.

lol_sum_row

Help on function lol_sum_row in module pydicts.lol:

lol_sum_row(row, from_index=0, to_index=None, zerovalue=0)
    Calculates the sum of values in a specific range of a row.
    None values are ignored.

    Args:
        row (list): The row (list of values) to sum.
        from_index (int, optional): The starting index for summing. Defaults to 0.
        to_index (int, optional): The ending index for summing. If None, sums to the end of the row.
                                  Defaults to None.
        zerovalue (int, float, Decimal, Currency, optional): The initial value for the sum.
                                                              Useful for summing custom objects like Currency. Defaults to 0.

    Returns:
        (int, float, Decimal, Currency): The sum of the values in the specified range.

lol_sum_column

Help on function lol_sum_column in module pydicts.lol:

lol_sum_column(lol, column, from_index, to_index, zerovalue=0)
    Calculates the sum of values in a specific column across a range of rows.
    None values are ignored.

    Args:
        lol (list): The list of lists.
        column (int): The index of the column to sum.
        from_index (int): The starting row index for summing.
        to_index (int): The ending row index for summing.
        zerovalue (int, float, Decimal, Currency, optional): The initial value for the sum.
                                                              Useful for summing custom objects like Currency. Defaults to 0.

    Returns:
        (int, float, Decimal, Currency): The sum of the values in the specified column and row range.