Skip to content

Commit f2c322f

Browse files
committed
Add 'flatten' option to data.append_to_list to handle list-to-list adds
1 parent 1529285 commit f2c322f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

netsim/data/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ def get_a_list(x: typing.Any, ctx: typing.Optional[str] = None) -> list:
3333
* Create an empty list if it does not exist
3434
* Append the item to the list
3535
"""
36-
def append_to_list(BX: typing.Optional[Box], list_name: str, item: typing.Any) -> list:
36+
def append_to_list(BX: typing.Optional[Box], list_name: str, item: typing.Any, flatten: bool = False) -> list:
3737
if BX is None:
3838
return []
3939

4040
if not list_name in BX:
4141
BX[list_name] = []
4242

4343
if not item in BX[list_name]:
44-
BX[list_name].append(item)
44+
if flatten and isinstance(item,list):
45+
BX[list_name].extend(item)
46+
else:
47+
BX[list_name].append(item)
4548

4649
return BX[list_name]
4750

0 commit comments

Comments
 (0)