Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions netsim/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,22 @@ def get_a_list(x: typing.Any, ctx: typing.Optional[str] = None) -> list:

* Return if the box is None
* Create an empty list if it does not exist
* Append the item to the list
* Convert a scalar value into a one-element list
* Append the item to the list if it's not already there
* With 'flatten' set, append the list elements that are not already in the list
"""
def append_to_list(BX: typing.Optional[Box], list_name: str, item: typing.Any, flatten: bool = False) -> list:
if BX is None:
return []

if not list_name in BX:
BX[list_name] = []
elif not isinstance(BX[list_name],list):
BX[list_name] = [ BX[list_name] ]

if not item in BX[list_name]:
if flatten and isinstance(item,list):
BX[list_name].extend(item)
else:
BX[list_name].append(item)
for element in item if flatten and isinstance(item,list) else [ item ]:
if not element in BX[list_name]:
BX[list_name].append(element)

return BX[list_name]

Expand Down
Loading