for_dict
Loop the list of list or dict and create a new dict to output.
Description
Loop the list of list or dict and create a new dict to output.
Parameters
Parameter |
Type |
Required |
Default |
Comment |
---|---|---|---|---|
filter | expression |
No |
None |
Condition not to add item for a crated dict. Loop item can be refereed as same as in expression. |
key | expression |
Yes |
- |
Expression of a item of key for a created dict. Item in the loop of list can be referred as item*. Item in the loop of dict can be referred as item*_val and item*_key. For the first loop item can be referred as item0. For the second loop item can be referred as item1. |
lists | list |
Yes |
- |
List of list or dict to make a nested loop. Single list or dict can be passed. |
out_bb | bool |
No |
False |
If this parameter is set to True, the data is stored in the blackboard rather than in the flowdata. By default, the key in the blackboard is set to the node name. To customize the key, specify the out_field parameter. |
out_field | str |
No |
None |
The key for the data in the blackboard. If out_bb is set to False, this parameter is ignored. |
val | expression |
Yes |
- |
Expression of of a item of value for a created dict. Loop item can be refereed as same as in key. |
Examples
# Create a dict from list of list and dict.
# Output: {'for_dict': {'head1:name1': 'val1', 'head1:name2': 'val2', 'head2:name1': 'val1', 'head2:name2': 'val2'}}
- for_dict:
name: "for_dict"
lists: [["head1", "head2"], {"name1": "val1", "name2": "val2"}]
key: "item0 + ':' + item1_key"
val: "item1_val"
# Create a dict from a single list.
# Output: {'for_dict': {"key1": 2, "key2": 4, "key3": 6}}
- for_dict:
name: "for_dict"
lists: [1, 2, 3, 4]
key: "'key' + item0 |str"
val: "item0*2"
filter: "item0*2>7"
# Create a dict from a dict.
# Output: {'for_dict': {"key1-1": 1, "key2-2": 2}}
- for_dict:
name: "for_dict"
lists: {"key1": 1, "key2": 2}
key: "item0_key + '-' + item0_val | str"
val: "item0_val"