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 |
|
out_field | str |
No |
None |
|
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"