main.list¶
Functions¶
combine_content_in_list ¶
Combine content in list with optional insertion flags.
Combines content from a list of strings or list of string lists, optionally inserting flags between each item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_list | list[str] | list[list[str]] | List of strings or list of string lists to combine. | required |
insert_flag | list[str] | str | None | Content to insert between items. Can be a string, list of strings, or None for no insertion. | None |
before_after | str | Position to insert flag - "before" or "after" each item. | 'after' |
Returns:
| Type | Description |
|---|---|
list[str] | List[str]: Combined list with optional insertions. |
Examples:
>>> combine_content_in_list(["a", "b"], "---")
['a', '---', 'b', '---']
>>> combine_content_in_list([["a", "b"], ["c", "d"]], "---")
['a', 'b', '---', 'c', 'd', '---']
Source code in pyadvtools/main/list.py
insert_list_in_list ¶
insert_list_in_list(
data_list,
insert_content_list,
insert_flag,
insert_before_after="after",
insert_times=1,
)
Insert content into a list at specified positions.
Inserts a list of content into another list either at a specific index or at positions matching a regex pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_list | list[str] | List to insert content into. | required |
insert_content_list | list[str] | Content to insert. | required |
insert_flag | int | str | Position indicator - integer index or regex pattern. | required |
insert_before_after | str | "before" or "after" the target position. | 'after' |
insert_times | float | Number of times to perform insertion (for regex). | 1 |
Returns:
| Type | Description |
|---|---|
list[str] | List[str]: New list with content inserted. |
Examples:
>>> insert_list_in_list(["a", "b", "c"], ["X", "Y"], 2)
['a', 'b', 'X', 'Y', 'c']
>>> insert_list_in_list(["a", "b", "c"], ["X"], "b", "before")
['a', 'X', 'b', 'c']
Source code in pyadvtools/main/list.py
pairwise_combine_in_list ¶
Pairwise combine two lists of lists.
Combines corresponding lists from two list-of-lists structures. The lists must have the same length.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_list_list_one | list[list[str]] | First list of lists to combine. | required |
data_list_list_two | list[list[str]] | Second list of lists to combine. | required |
mid_flag | str | list | Content to insert between combined lists. | '\n' |
Returns:
| Type | Description |
|---|---|
list[list[str]] | List[List[str]]: List of combined lists, or empty list if lengths don't match. |
Examples:
Source code in pyadvtools/main/list.py
substitute_in_list ¶
Substitute patterns in list elements.
Performs regex substitutions on each element of a list, replacing patterns from old_list with corresponding patterns from new_list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
old_list | list[str] | List of regex patterns to find. | required |
new_list | list[str] | List of replacement patterns (must match old_list length). | required |
data_list | list[str] | List of strings to perform substitutions on. | required |
Returns:
| Type | Description |
|---|---|
list[str] | List[str]: List with substitutions applied, or original list if old_list and new_list lengths don't match. |
Examples: