<jupyter_start><jupyter_text>How to attach variables to step output * **Difficulty level**: intermediate* **Time need to lean**: 15 minutes or less* **Key points**:  *     Reminder If a SoS step contains multiple substeps, defined by options `group_by` or `for_each`, the `_input` becomes the groups of `step_input` and `_output` becomes the groups of `step_output`, and the steps are executed for each of the groups.Moreover, the group information of `step_output` will be passed as the default input to the next step in a simple forward-style workflow, or as input to another step with functions `output_from` or `named_output`. As shown in the following example, the `step_output` of step `A` becomes the input of step `B`, creating two substeps.<jupyter_code>!touch a.txt b.txt

%run B -v0

[A]
input: 'a.txt', 'b.txt', group_by=1
output: _input.with_suffix('.bak')

_output.touch()
print(f'step_input={step_input}, _input={_input}, _output={_output}')

[B]
input: output_from('A')
print(f'step_output={step_input}, _output={_input}')<jupyter_output><empty_output><jupyter_text>Attaching group information to `step_output` As we<jupyter_code>%run B -v0

[A]
input: 'a.txt', 'b.txt', group_by=1
output: _input.with_suffix('.bak')

_output.touch()
print(f'step_input={step_input}, _input={_input}, _output={_output}')

[B]
input: output_from('A')
print(f'step_output={step_input}, _output={_input}')<jupyter_output><empty_output><jupyter_text>The group_with output option      The `group_with` output option Just like the `group_with` option of the `input` statement, the `group_with` output option assigns a sequence of variables to each of the output groups (variable `_output`).<jupyter_code>!touch a.txt b.txt

%run -v0

samples = ['A', 'B']

[1]
input: 'a.txt', 'b.txt', group_by=1
output: _input.with_suffix('.bak'), group_with=dict(sample=samples)

_output.touch()
print(f'step_input={step_input}, _input={_input}, _output={_output}, _output.sample={_output.sample}')

[2]
print(f'step_output={step_input}, _output={_input}, _output.sample={_input.sample}')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13979007633587787, 'fraction_numerical': 0.004770992366412214, 'mean_word_length': 6.824626865671642, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '600190', 'license': 'MIT', 'n_tokens_mistral': 721, 'n_tokens_neox': 719, 'n_words': 212, 'path': 'src/user_guide/output_groups_vars.ipynb', 'repo_name': 'andrewrocks/sos-docs', 'size': '2096'}