<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mscneuro.neuro.uni-bremen.de/index.php?action=history&amp;feed=atom&amp;title=Flow_Control%3A_match_case</id>
	<title>Flow Control: match case - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mscneuro.neuro.uni-bremen.de/index.php?action=history&amp;feed=atom&amp;title=Flow_Control%3A_match_case"/>
	<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Flow_Control:_match_case&amp;action=history"/>
	<updated>2026-09-25T06:15:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://mscneuro.neuro.uni-bremen.de/index.php?title=Flow_Control:_match_case&amp;diff=318&amp;oldid=prev</id>
		<title>Davrot at 16:07, 17 October 2025</title>
		<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Flow_Control:_match_case&amp;diff=318&amp;oldid=prev"/>
		<updated>2025-10-17T16:07:41Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 16:07, 17 October 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;== The goal ==&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;There is a new flow control in town. A switch case replacement, called match case.&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;There is a new flow control in town. A switch case replacement, called match case.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l34&quot;&gt;Line 34:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 33:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Unpacking parameters ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Unpacking parameters ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{: .topic-optional} &lt;/del&gt;This is an optional topic!&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;This is an optional topic!&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Different from a normal switch we can deal with several input parameters at the same time and even use wildcards:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Different from a normal switch we can deal with several input parameters at the same time and even use wildcards:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l85&quot;&gt;Line 85:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 86:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== OR ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== OR ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{: .topic-optional} &lt;/del&gt;This is an optional topic!&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;This is an optional topic!&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We can combine patter by | (or):&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We can combine patter by | (or):&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l152&quot;&gt;Line 152:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 155:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== If guards ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== If guards ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{: .topic-optional} &lt;/del&gt;This is an optional topic!&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;This is an optional topic!&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We can distinguish between cases by using &amp;#039;&amp;#039;&amp;#039;if guard&amp;#039;&amp;#039;&amp;#039;:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We can distinguish between cases by using &amp;#039;&amp;#039;&amp;#039;if guard&amp;#039;&amp;#039;&amp;#039;:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l187&quot;&gt;Line 187:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 192:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Data classes ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Data classes ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{: .topic-optional} &lt;/del&gt;This is an optional topic!&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;This is an optional topic!&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We can combine it nicely with data classes:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from dataclasses import dataclass&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We can combine it nicely with data classes:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from dataclasses import dataclass&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l238&quot;&gt;Line 238:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 245:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== As ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== As ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{: .topic-optional} &lt;/del&gt;This is an optional topic!&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;This is an optional topic!&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We can use &amp;#039;&amp;#039;&amp;#039;as&amp;#039;&amp;#039;&amp;#039; to name a variable in a case clause (if you have a sequence i.e. tuple or list of elements then you can use &amp;#039;&amp;#039;&amp;#039;as&amp;#039;&amp;#039;&amp;#039; on the individual elements): &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from dataclasses import dataclass&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;We can use &amp;#039;&amp;#039;&amp;#039;as&amp;#039;&amp;#039;&amp;#039; to name a variable in a case clause (if you have a sequence i.e. tuple or list of elements then you can use &amp;#039;&amp;#039;&amp;#039;as&amp;#039;&amp;#039;&amp;#039; on the individual elements): &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from dataclasses import dataclass&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l289&quot;&gt;Line 289:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 298:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== List ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== List ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{: .topic-optional} &lt;/del&gt;This is an optional topic!&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;This is an optional topic!&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This is how we can deal with lists that have different length:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This is how we can deal with lists that have different length:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l332&quot;&gt;Line 332:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 343:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Dictionaries ===&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;=== Dictionaries ===&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;{: .topic-optional} &lt;/del&gt;This is an optional topic!&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;This is an optional topic!&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&#039;&#039;&#039;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt; &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The whole match apparatus works also with dictionaries. You can even distinguish between what kind of variable is stored behind a key (e.g. int vs str): &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;The whole match apparatus works also with dictionaries. You can even distinguish between what kind of variable is stored behind a key (e.g. int vs str): &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki:diff:1.41:old-142:rev-318:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>Davrot</name></author>
	</entry>
	<entry>
		<id>https://mscneuro.neuro.uni-bremen.de/index.php?title=Flow_Control:_match_case&amp;diff=142&amp;oldid=prev</id>
		<title>Davrot: Created page with &quot; == The goal == There is a new flow control in town. A switch case replacement, called match case.  Questions to [mailto:davrot@uni-bremen.de David Rotermund]  == The [https://docs.python.org/3/reference/compound_stmts.html#the-match-statement match] statement == The match statement is used for pattern matching. Syntax:&lt;syntaxhighlight lang=&quot;python&quot;&gt;match_stmt   ::=  &#039;match&#039; subject_expr &quot;:&quot; NEWLINE INDENT case_block+ DEDENT subject_expr ::=  star_named_expression &quot;,&quot; st...&quot;</title>
		<link rel="alternate" type="text/html" href="https://mscneuro.neuro.uni-bremen.de/index.php?title=Flow_Control:_match_case&amp;diff=142&amp;oldid=prev"/>
		<updated>2025-10-15T11:02:29Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; == The goal == There is a new flow control in town. A switch case replacement, called match case.  Questions to [mailto:davrot@uni-bremen.de David Rotermund]  == The [https://docs.python.org/3/reference/compound_stmts.html#the-match-statement match] statement == The match statement is used for pattern matching. Syntax:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;match_stmt   ::=  &amp;#039;match&amp;#039; subject_expr &amp;quot;:&amp;quot; NEWLINE INDENT case_block+ DEDENT subject_expr ::=  star_named_expression &amp;quot;,&amp;quot; st...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
== The goal ==&lt;br /&gt;
There is a new flow control in town. A switch case replacement, called match case.&lt;br /&gt;
&lt;br /&gt;
Questions to [mailto:davrot@uni-bremen.de David Rotermund]&lt;br /&gt;
&lt;br /&gt;
== The [https://docs.python.org/3/reference/compound_stmts.html#the-match-statement match] statement ==&lt;br /&gt;
The match statement is used for pattern matching. Syntax:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;match_stmt   ::=  &amp;#039;match&amp;#039; subject_expr &amp;quot;:&amp;quot; NEWLINE INDENT case_block+ DEDENT&lt;br /&gt;
subject_expr ::=  star_named_expression &amp;quot;,&amp;quot; star_named_expressions?&lt;br /&gt;
                  | named_expression&lt;br /&gt;
case_block   ::=  &amp;#039;case&amp;#039; patterns [guard] &amp;quot;:&amp;quot; block&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Normal “switch” case ==&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;for i in range(0, 4):&lt;br /&gt;
&lt;br /&gt;
    match (i):&lt;br /&gt;
        case 0:&lt;br /&gt;
            print(&amp;quot;This is a 0&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        case 0:&lt;br /&gt;
            print(&amp;quot;This is a 0 too.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        case 1:&lt;br /&gt;
            print(&amp;quot;This is a 1.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        case 2:&lt;br /&gt;
            print(&amp;quot;This is a 2.&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        case _:&lt;br /&gt;
            print(f&amp;quot;I don&amp;#039;t know what to do with a {i}!&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;Output:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;This is a 0&lt;br /&gt;
This is a 1.&lt;br /&gt;
This is a 2.&lt;br /&gt;
I don&amp;#039;t know what to do with a 3!&amp;lt;/syntaxhighlight&amp;gt;_ is the default. And after every case state has an in-build &amp;#039;&amp;#039;&amp;#039;break;&amp;#039;&amp;#039;&amp;#039; (If you don’t know what this means: A. You are not a C/C++ programmer. B. You can ignore this information. :-) ).&lt;br /&gt;
&lt;br /&gt;
== Unpacking parameters ==&lt;br /&gt;
{: .topic-optional} This is an optional topic!&lt;br /&gt;
&lt;br /&gt;
Different from a normal switch we can deal with several input parameters at the same time and even use wildcards:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;br /&gt;
    match (input):&lt;br /&gt;
        case (0, 0):&lt;br /&gt;
            print(&amp;quot;This is (0,0) - A&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        case (0, 1):&lt;br /&gt;
            print(&amp;quot;This is (0,1) - B&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        case (x, 0):&lt;br /&gt;
            print(f&amp;quot;This is a {x} - C&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        case (x, y):&lt;br /&gt;
            print(f&amp;quot;This is a {x} and {y} - D&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        case _:&lt;br /&gt;
            print(f&amp;quot;I don&amp;#039;t know what to do with {input}- E!&amp;quot;)&lt;br /&gt;
    print(&amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
second_parameter: int = 0&lt;br /&gt;
for i in range(0, 2):&lt;br /&gt;
    input = (i, second_parameter)&lt;br /&gt;
    print(f&amp;quot;Input: {input}&amp;quot;)&lt;br /&gt;
    what_to_do(input)&lt;br /&gt;
&lt;br /&gt;
second_parameter = 1&lt;br /&gt;
for i in range(0, 2):&lt;br /&gt;
    input = (i, second_parameter)&lt;br /&gt;
    print(f&amp;quot;Input: {input}&amp;quot;)&lt;br /&gt;
    what_to_do(input)&lt;br /&gt;
&lt;br /&gt;
input = &amp;quot;Hello!&amp;quot;&lt;br /&gt;
print(f&amp;quot;Input: {input}&amp;quot;)&lt;br /&gt;
what_to_do(input)&amp;lt;/syntaxhighlight&amp;gt;Output:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;Input: (0, 0)&lt;br /&gt;
This is (0,0) - A&lt;br /&gt;
&lt;br /&gt;
Input: (1, 0)&lt;br /&gt;
This is a 1 - C&lt;br /&gt;
&lt;br /&gt;
Input: (0, 1)&lt;br /&gt;
This is (0,1) - B&lt;br /&gt;
&lt;br /&gt;
Input: (1, 1)&lt;br /&gt;
This is a 1 and 1 - D&lt;br /&gt;
&lt;br /&gt;
Input: Hello!&lt;br /&gt;
I don&amp;#039;t know what to do with Hello!- E!&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== OR ===&lt;br /&gt;
{: .topic-optional} This is an optional topic!&lt;br /&gt;
&lt;br /&gt;
We can combine patter by | (or):&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;br /&gt;
    match (input):&lt;br /&gt;
        case (0, 0) | (0, 1):&lt;br /&gt;
            print(&amp;quot;This is (0,0) or (0,1) - A&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        case (x, 0):&lt;br /&gt;
            print(f&amp;quot;This is a {x} - C&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        case (x, y):&lt;br /&gt;
            print(f&amp;quot;This is a {x} and {y} - D&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        case _:&lt;br /&gt;
            print(f&amp;quot;I don&amp;#039;t know what to do with {input}- E!&amp;quot;)&lt;br /&gt;
    print(&amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
second_parameter: int = 0&lt;br /&gt;
for i in range(0, 2):&lt;br /&gt;
    input = (i, second_parameter)&lt;br /&gt;
    print(f&amp;quot;Input: {input}&amp;quot;)&lt;br /&gt;
    what_to_do(input)&lt;br /&gt;
&lt;br /&gt;
second_parameter = 1&lt;br /&gt;
for i in range(0, 2):&lt;br /&gt;
    input = (i, second_parameter)&lt;br /&gt;
    print(f&amp;quot;Input: {input}&amp;quot;)&lt;br /&gt;
    what_to_do(input)&amp;lt;/syntaxhighlight&amp;gt;Output:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;Input: (0, 0)&lt;br /&gt;
This is (0,0) or (0,1) - A&lt;br /&gt;
&lt;br /&gt;
Input: (1, 0)&lt;br /&gt;
This is a 1 - C&lt;br /&gt;
&lt;br /&gt;
Input: (0, 1)&lt;br /&gt;
This is (0,0) or (0,1) - A&lt;br /&gt;
&lt;br /&gt;
Input: (1, 1)&lt;br /&gt;
This is a 1 and 1 - D&amp;lt;/syntaxhighlight&amp;gt;You can also use the &amp;#039;&amp;#039;&amp;#039;or&amp;#039;&amp;#039;&amp;#039; on parts of the pattern (output is the same as before):&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;br /&gt;
    match (input):&lt;br /&gt;
        case (0, (0 | 1)):&lt;br /&gt;
            print(&amp;quot;This is (0,0) or (0,1) - A&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        case (x, 0):&lt;br /&gt;
            print(f&amp;quot;This is a {x} - C&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        case (x, y):&lt;br /&gt;
            print(f&amp;quot;This is a {x} and {y} - D&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
        case _:&lt;br /&gt;
            print(f&amp;quot;I don&amp;#039;t know what to do with {input}- E!&amp;quot;)&lt;br /&gt;
    print(&amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
second_parameter: int = 0&lt;br /&gt;
for i in range(0, 2):&lt;br /&gt;
    input = (i, second_parameter)&lt;br /&gt;
    print(f&amp;quot;Input: {input}&amp;quot;)&lt;br /&gt;
    what_to_do(input)&lt;br /&gt;
&lt;br /&gt;
second_parameter = 1&lt;br /&gt;
for i in range(0, 2):&lt;br /&gt;
    input = (i, second_parameter)&lt;br /&gt;
    print(f&amp;quot;Input: {input}&amp;quot;)&lt;br /&gt;
    what_to_do(input)&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== If guards ===&lt;br /&gt;
{: .topic-optional} This is an optional topic!&lt;br /&gt;
&lt;br /&gt;
We can distinguish between cases by using &amp;#039;&amp;#039;&amp;#039;if guard&amp;#039;&amp;#039;&amp;#039;:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;br /&gt;
    match (input):&lt;br /&gt;
        case (x, y) if x == y:&lt;br /&gt;
            print(f&amp;quot;Both are {x} - A &amp;quot;)&lt;br /&gt;
        case (x, y):&lt;br /&gt;
            print(f&amp;quot;This is a {x} and {y} - B &amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
second_parameter: int = 0&lt;br /&gt;
for i in range(0, 2):&lt;br /&gt;
    input = (i, second_parameter)&lt;br /&gt;
    print(f&amp;quot;Input: {input}&amp;quot;)&lt;br /&gt;
    what_to_do(input)&lt;br /&gt;
&lt;br /&gt;
second_parameter = 1&lt;br /&gt;
for i in range(0, 2):&lt;br /&gt;
    input = (i, second_parameter)&lt;br /&gt;
    print(f&amp;quot;Input: {input}&amp;quot;)&lt;br /&gt;
    what_to_do(input)&amp;lt;/syntaxhighlight&amp;gt;Output:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;Input: (0, 0)&lt;br /&gt;
Both are 0 - A &lt;br /&gt;
&lt;br /&gt;
Input: (1, 0)&lt;br /&gt;
This is a 1 and 0 - B &lt;br /&gt;
&lt;br /&gt;
Input: (0, 1)&lt;br /&gt;
This is a 0 and 1 - B &lt;br /&gt;
&lt;br /&gt;
Input: (1, 1)&lt;br /&gt;
Both are 1 - A &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Data classes ===&lt;br /&gt;
{: .topic-optional} This is an optional topic!&lt;br /&gt;
&lt;br /&gt;
We can combine it nicely with data classes:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from dataclasses import dataclass&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
@dataclass&lt;br /&gt;
class SomeDataStructure:&lt;br /&gt;
    x: int&lt;br /&gt;
    y: int&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def what_to_do(input):&lt;br /&gt;
    print(input)&lt;br /&gt;
    match (input):&lt;br /&gt;
        case SomeDataStructure(x=0, y=0):&lt;br /&gt;
            print(&amp;quot;case A&amp;quot;)&lt;br /&gt;
        case SomeDataStructure(x=1, y=0):&lt;br /&gt;
            print(&amp;quot;case B&amp;quot;)&lt;br /&gt;
        case SomeDataStructure():&lt;br /&gt;
            print(&amp;quot;case C&amp;quot;)&lt;br /&gt;
        case _:&lt;br /&gt;
            print(&amp;quot;What?&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
data_0_0 = SomeDataStructure(0, 0)&lt;br /&gt;
what_to_do(data_0_0)&lt;br /&gt;
data_0_1 = SomeDataStructure(0, 1)&lt;br /&gt;
what_to_do(data_0_1)&lt;br /&gt;
data_1_0 = SomeDataStructure(1, 0)&lt;br /&gt;
what_to_do(data_1_0)&lt;br /&gt;
data_1_1 = SomeDataStructure(1, 1)&lt;br /&gt;
what_to_do(data_1_1)&lt;br /&gt;
data_broken = &amp;quot;I am broken!&amp;quot;&lt;br /&gt;
what_to_do(data_broken)&amp;lt;/syntaxhighlight&amp;gt;Output:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;SomeDataStructure(x=0, y=0)&lt;br /&gt;
case A&lt;br /&gt;
&lt;br /&gt;
SomeDataStructure(x=0, y=1)&lt;br /&gt;
case C&lt;br /&gt;
&lt;br /&gt;
SomeDataStructure(x=1, y=0)&lt;br /&gt;
case B&lt;br /&gt;
&lt;br /&gt;
SomeDataStructure(x=1, y=1)&lt;br /&gt;
case C&lt;br /&gt;
&lt;br /&gt;
I am broken!&lt;br /&gt;
What?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== As ===&lt;br /&gt;
{: .topic-optional} This is an optional topic!&lt;br /&gt;
&lt;br /&gt;
We can use &amp;#039;&amp;#039;&amp;#039;as&amp;#039;&amp;#039;&amp;#039; to name a variable in a case clause (if you have a sequence i.e. tuple or list of elements then you can use &amp;#039;&amp;#039;&amp;#039;as&amp;#039;&amp;#039;&amp;#039; on the individual elements): &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;from dataclasses import dataclass&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
@dataclass&lt;br /&gt;
class SomeDataStructure:&lt;br /&gt;
    x: int&lt;br /&gt;
    y: int&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
def what_to_do(input):&lt;br /&gt;
    print(input)&lt;br /&gt;
    match (input):&lt;br /&gt;
        case SomeDataStructure(x=0, y=0):&lt;br /&gt;
            print(&amp;quot;case A&amp;quot;)&lt;br /&gt;
        case SomeDataStructure(x=1, y=0):&lt;br /&gt;
            print(&amp;quot;case B&amp;quot;)&lt;br /&gt;
        case SomeDataStructure() as someinput:&lt;br /&gt;
            print(f&amp;quot;case C : {someinput.x} {someinput.y}&amp;quot;)&lt;br /&gt;
        case _:&lt;br /&gt;
            print(&amp;quot;What?&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
data_0_0 = SomeDataStructure(0, 0)&lt;br /&gt;
what_to_do(data_0_0)&lt;br /&gt;
data_0_1 = SomeDataStructure(0, 1)&lt;br /&gt;
what_to_do(data_0_1)&lt;br /&gt;
data_1_0 = SomeDataStructure(1, 0)&lt;br /&gt;
what_to_do(data_1_0)&lt;br /&gt;
data_1_1 = SomeDataStructure(1, 1)&lt;br /&gt;
what_to_do(data_1_1)&lt;br /&gt;
data_broken = &amp;quot;I am broken!&amp;quot;&lt;br /&gt;
what_to_do(data_broken)&amp;lt;/syntaxhighlight&amp;gt;Output:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;SomeDataStructure(x=0, y=0)&lt;br /&gt;
case A&lt;br /&gt;
&lt;br /&gt;
SomeDataStructure(x=0, y=1)&lt;br /&gt;
case C : 0 1&lt;br /&gt;
&lt;br /&gt;
SomeDataStructure(x=1, y=0)&lt;br /&gt;
case B&lt;br /&gt;
&lt;br /&gt;
SomeDataStructure(x=1, y=1)&lt;br /&gt;
case C : 1 1&lt;br /&gt;
&lt;br /&gt;
I am broken!&lt;br /&gt;
What?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== List ===&lt;br /&gt;
{: .topic-optional} This is an optional topic!&lt;br /&gt;
&lt;br /&gt;
This is how we can deal with lists that have different length:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;br /&gt;
    print(input)&lt;br /&gt;
    match (input):&lt;br /&gt;
        case []:&lt;br /&gt;
            print(&amp;quot;case A&amp;quot;)&lt;br /&gt;
        case [0]:&lt;br /&gt;
            print(&amp;quot;case B&amp;quot;)&lt;br /&gt;
        case [x]:&lt;br /&gt;
            print(f&amp;quot;case C {x}&amp;quot;)&lt;br /&gt;
        case [0, 0]:&lt;br /&gt;
            print(&amp;quot;case D&amp;quot;)&lt;br /&gt;
        case _:&lt;br /&gt;
            print(&amp;quot;What?&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
    print(&amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
what_to_do([])&lt;br /&gt;
what_to_do([0])&lt;br /&gt;
what_to_do([1])&lt;br /&gt;
what_to_do([0, 0])&lt;br /&gt;
what_to_do([0, 1])&lt;br /&gt;
what_to_do(&amp;quot;Hello&amp;quot;)&amp;lt;/syntaxhighlight&amp;gt;Output:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;[]&lt;br /&gt;
case A&lt;br /&gt;
&lt;br /&gt;
[0]&lt;br /&gt;
case B&lt;br /&gt;
&lt;br /&gt;
[1]&lt;br /&gt;
case C 1&lt;br /&gt;
&lt;br /&gt;
[0, 0]&lt;br /&gt;
case D&lt;br /&gt;
&lt;br /&gt;
[0, 1]&lt;br /&gt;
What?&lt;br /&gt;
&lt;br /&gt;
Hello&lt;br /&gt;
What?&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Dictionaries ===&lt;br /&gt;
{: .topic-optional} This is an optional topic!&lt;br /&gt;
&lt;br /&gt;
The whole match apparatus works also with dictionaries. You can even distinguish between what kind of variable is stored behind a key (e.g. int vs str): &amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;def what_to_do(input):&lt;br /&gt;
    print(input)&lt;br /&gt;
    match (input):&lt;br /&gt;
        case {&amp;quot;x&amp;quot;: str() as x}:&lt;br /&gt;
            print(f&amp;quot;{x} - str&amp;quot;)&lt;br /&gt;
        case {&amp;quot;x&amp;quot;: int() as x}:&lt;br /&gt;
            print(f&amp;quot;{x} - int&amp;quot;)&lt;br /&gt;
        case {&amp;quot;y&amp;quot;: value}:&lt;br /&gt;
            print(f&amp;quot;{value} - A&amp;quot;)&lt;br /&gt;
        case {&amp;quot;a&amp;quot;: value_a, &amp;quot;b&amp;quot;: value_b}:&lt;br /&gt;
            print(f&amp;quot;a={value_a} b={value_b} - B&amp;quot;)&lt;br /&gt;
    print(&amp;quot;&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
dictionary_a = {&amp;quot;x&amp;quot;: str(1)}&lt;br /&gt;
what_to_do(dictionary_a)&lt;br /&gt;
dictionary_b = {&amp;quot;x&amp;quot;: int(1)}&lt;br /&gt;
what_to_do(dictionary_b)&lt;br /&gt;
dictionary_c = {&amp;quot;x&amp;quot;: int(1), &amp;quot;y&amp;quot;: 5}&lt;br /&gt;
what_to_do(dictionary_c)&lt;br /&gt;
dictionary_d = {&amp;quot;y&amp;quot;: 5}&lt;br /&gt;
what_to_do(dictionary_d)&lt;br /&gt;
dictionary_e = {&amp;quot;a&amp;quot;: 6, &amp;quot;b&amp;quot;: 7}&lt;br /&gt;
what_to_do(dictionary_e)&lt;br /&gt;
dictionary_f = {&amp;quot;b&amp;quot;: 8, &amp;quot;a&amp;quot;: 10}&lt;br /&gt;
what_to_do(dictionary_f)&amp;lt;/syntaxhighlight&amp;gt;Output:&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;{&amp;#039;x&amp;#039;: &amp;#039;1&amp;#039;}&lt;br /&gt;
1 - str&lt;br /&gt;
&lt;br /&gt;
{&amp;#039;x&amp;#039;: 1}&lt;br /&gt;
1 - int&lt;br /&gt;
&lt;br /&gt;
{&amp;#039;x&amp;#039;: 1, &amp;#039;y&amp;#039;: 5}&lt;br /&gt;
1 - int&lt;br /&gt;
&lt;br /&gt;
{&amp;#039;y&amp;#039;: 5}&lt;br /&gt;
5 - A&lt;br /&gt;
&lt;br /&gt;
{&amp;#039;a&amp;#039;: 6, &amp;#039;b&amp;#039;: 7}&lt;br /&gt;
a=6 b=7 - B&lt;br /&gt;
&lt;br /&gt;
{&amp;#039;b&amp;#039;: 8, &amp;#039;a&amp;#039;: 10}&lt;br /&gt;
a=10 b=8 - B&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Reference ==&lt;br /&gt;
&lt;br /&gt;
* [https://peps.python.org/pep-0636/ PEP 636 – Structural Pattern Matching: Tutorial]&lt;/div&gt;</summary>
		<author><name>Davrot</name></author>
	</entry>
</feed>