<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?action=history&amp;feed=atom&amp;title=Intermediate_classes</id>
	<title>Intermediate classes - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?action=history&amp;feed=atom&amp;title=Intermediate_classes"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;action=history"/>
	<updated>2026-06-10T19:37:27Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=288&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=288&amp;oldid=prev"/>
		<updated>2026-03-23T10:06:12Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&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 12:06, 23 March 2026&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-l17&quot;&gt;Line 17:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 17:&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 first four exercises will continue with the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class from last time.&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 first four exercises will continue with the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class from last time.&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;div&gt;# Use magic methods to add &amp;#039;&amp;#039;iteration&amp;#039;&amp;#039; and &amp;#039;&amp;#039;length&amp;#039;&amp;#039; evaluation (using &amp;#039;&amp;#039;&amp;#039;__iter__&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;__len__&amp;#039;&amp;#039;&amp;#039; magic methods) to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;The function &amp;#039;&amp;#039;&amp;#039;len&amp;#039;&amp;#039;&amp;#039; returns the number of sequences.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Use magic methods to add &amp;#039;&amp;#039;iteration&amp;#039;&amp;#039; and &amp;#039;&amp;#039;length&amp;#039;&amp;#039; evaluation (using &amp;#039;&amp;#039;&amp;#039;__iter__&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;__len__&amp;#039;&amp;#039;&amp;#039; magic methods) to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;The function &amp;#039;&amp;#039;&amp;#039;len&amp;#039;&amp;#039;&amp;#039; returns the number of sequences.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Add the methods &#039;&#039;&#039;deletethis()&#039;&#039;&#039;, &#039;&#039;&#039;insertthis(header, sequence)&#039;&#039;&#039;, &#039;&#039;&#039;verifythis(alphabet)&#039;&#039;&#039; and &#039;&#039;&#039;discardthis(alphabet)&#039;&#039;&#039; to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class. The methods should only work when &#039;&#039;iterating over an instance at the current item&#039;&#039;, i.e. they work when you are iterating over the fasta sequences on the &#039;&#039;current&#039;&#039; sequence and header, like this:&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&quot;DNA&quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible. Hint: change the way your iteration works in the previous exercise. You need to take a position on this issue: When iterating over entries, how should you continue after inserting entries at your current position? Example: You are at element in position 5, you insert 2 elements at that position. This WILL mean the new elements are at position 5 and 6, and the one you &quot;looked at&quot; is now on position 7. Do you continue the iteration on position 5 or is the next position 8? My opinion is that you should not look at the new elements and you have already looked at the &quot;old&quot; element at 5, so the next one is at 8. You are free to make your own decision - just be clear about it. &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Just realize &lt;/del&gt;if you insert something because you see a special &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;elements &lt;/del&gt;and you do not choose my way, then you will create an infinite loop, since you will see the special element again.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Add the methods &#039;&#039;&#039;deletethis()&#039;&#039;&#039;, &#039;&#039;&#039;insertthis(header, sequence)&#039;&#039;&#039;, &#039;&#039;&#039;verifythis(alphabet)&#039;&#039;&#039; and &#039;&#039;&#039;discardthis(alphabet)&#039;&#039;&#039; to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class. The methods should only work when &#039;&#039;iterating over an instance at the current item&#039;&#039;, i.e. they work when you are iterating over the fasta sequences on the &#039;&#039;current&#039;&#039; sequence and header, like this:&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&quot;DNA&quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible. Hint: change the way your iteration works in the previous exercise. You need to take a position on this issue: When iterating over entries, how should you continue after inserting entries at your current position? Example: You are at element in position 5, you insert 2 elements at that position. This WILL mean the new elements are at position 5 and 6, and the one you &quot;looked at&quot; is now on position 7. Do you continue the iteration on position 5 or is the next position 8? My opinion is that you should not look at the new elements and you have already looked at the &quot;old&quot; element at 5, so the next one is at 8. You are free to make your own decision - just be clear about it. &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Realize &lt;/ins&gt;if you insert something because you see a special &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;element &lt;/ins&gt;and you do not choose my way, then you will create an infinite loop, since you will see the special element again.&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# Let&amp;#039;s do something natural. Make it possible to add one FastaInstance to another using the &amp;#039;&amp;#039;&amp;#039;+=&amp;#039;&amp;#039;&amp;#039; operator, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance1 += FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The headers and sequences in Fastainstance2 should be added (list extension) to the headers and sequences in FastaInstance1. Use the magic method [https://zetcode.com/python/dunder-iadd/ &amp;#039;&amp;#039;&amp;#039;__iadd__&amp;#039;&amp;#039;&amp;#039;]. Try with the files &amp;#039;&amp;#039;dna7.fsa&amp;#039;&amp;#039; and &amp;#039;&amp;#039;protein.fsa&amp;#039;&amp;#039;. That will be a strange DNA and protein mix, but it is a great opportunity to use the &amp;#039;&amp;#039;&amp;#039;discard&amp;#039;&amp;#039;&amp;#039; method to get rid of one of the types.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Let&amp;#039;s do something natural. Make it possible to add one FastaInstance to another using the &amp;#039;&amp;#039;&amp;#039;+=&amp;#039;&amp;#039;&amp;#039; operator, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance1 += FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The headers and sequences in Fastainstance2 should be added (list extension) to the headers and sequences in FastaInstance1. Use the magic method [https://zetcode.com/python/dunder-iadd/ &amp;#039;&amp;#039;&amp;#039;__iadd__&amp;#039;&amp;#039;&amp;#039;]. Try with the files &amp;#039;&amp;#039;dna7.fsa&amp;#039;&amp;#039; and &amp;#039;&amp;#039;protein.fsa&amp;#039;&amp;#039;. That will be a strange DNA and protein mix, but it is a great opportunity to use the &amp;#039;&amp;#039;&amp;#039;discard&amp;#039;&amp;#039;&amp;#039; method to get rid of one of the types.&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# Implement the &amp;#039;&amp;#039;addition&amp;#039;&amp;#039;, using [https://zetcode.com/python/dunder-add/ &amp;#039;&amp;#039;&amp;#039;__add__&amp;#039;&amp;#039;&amp;#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor. Now that the Fasta class is done, save it in a file, so you can import it for the next exercises.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Implement the &amp;#039;&amp;#039;addition&amp;#039;&amp;#039;, using [https://zetcode.com/python/dunder-add/ &amp;#039;&amp;#039;&amp;#039;__add__&amp;#039;&amp;#039;&amp;#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor. Now that the Fasta class is done, save it in a file, so you can import it for the next exercises.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key c22118:diff:1.41:old-287:rev-288:php=table --&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=287&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=287&amp;oldid=prev"/>
		<updated>2026-03-23T10:05:41Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&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 12:05, 23 March 2026&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-l17&quot;&gt;Line 17:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 17:&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 first four exercises will continue with the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class from last time.&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 first four exercises will continue with the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class from last time.&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;div&gt;# Use magic methods to add &amp;#039;&amp;#039;iteration&amp;#039;&amp;#039; and &amp;#039;&amp;#039;length&amp;#039;&amp;#039; evaluation (using &amp;#039;&amp;#039;&amp;#039;__iter__&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;__len__&amp;#039;&amp;#039;&amp;#039; magic methods) to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;The function &amp;#039;&amp;#039;&amp;#039;len&amp;#039;&amp;#039;&amp;#039; returns the number of sequences.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Use magic methods to add &amp;#039;&amp;#039;iteration&amp;#039;&amp;#039; and &amp;#039;&amp;#039;length&amp;#039;&amp;#039; evaluation (using &amp;#039;&amp;#039;&amp;#039;__iter__&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;__len__&amp;#039;&amp;#039;&amp;#039; magic methods) to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;The function &amp;#039;&amp;#039;&amp;#039;len&amp;#039;&amp;#039;&amp;#039; returns the number of sequences.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Add the methods &#039;&#039;&#039;deletethis()&#039;&#039;&#039;, &#039;&#039;&#039;insertthis(header, sequence)&#039;&#039;&#039;, &#039;&#039;&#039;verifythis(alphabet)&#039;&#039;&#039; and &#039;&#039;&#039;discardthis(alphabet)&#039;&#039;&#039; to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class. The methods should only work when &#039;&#039;iterating over an instance at the current item&#039;&#039;, i.e. they work when you are iterating over the fasta sequences on the &#039;&#039;current&#039;&#039; sequence and header, like this:&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&quot;DNA&quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible. Hint: change the way your iteration works in the previous exercise. You need to take a position on this issue: When iterating over entries, how should you continue after inserting entries at your current position? Example: You are at element in position 5, you insert 2 elements at that position. This WILL mean the new elements are at position 5 and 6, and the one you &quot;looked at&quot; is now on position 7. Do you continue the iteration on position 5 or is the next position 8? My opinion is that you should not look at the new elements and you have already looked at the &quot;old&quot; element &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;ant &lt;/del&gt;5, so the next one is at 8. You are free to make your own decision - just be clear about it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Add the methods &#039;&#039;&#039;deletethis()&#039;&#039;&#039;, &#039;&#039;&#039;insertthis(header, sequence)&#039;&#039;&#039;, &#039;&#039;&#039;verifythis(alphabet)&#039;&#039;&#039; and &#039;&#039;&#039;discardthis(alphabet)&#039;&#039;&#039; to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class. The methods should only work when &#039;&#039;iterating over an instance at the current item&#039;&#039;, i.e. they work when you are iterating over the fasta sequences on the &#039;&#039;current&#039;&#039; sequence and header, like this:&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&quot;DNA&quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible. Hint: change the way your iteration works in the previous exercise. You need to take a position on this issue: When iterating over entries, how should you continue after inserting entries at your current position? Example: You are at element in position 5, you insert 2 elements at that position. This WILL mean the new elements are at position 5 and 6, and the one you &quot;looked at&quot; is now on position 7. Do you continue the iteration on position 5 or is the next position 8? My opinion is that you should not look at the new elements and you have already looked at the &quot;old&quot; element &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;at &lt;/ins&gt;5, so the next one is at 8. You are free to make your own decision - just be clear about it&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. Just realize if you insert something because you see a special elements and you do not choose my way, then you will create an infinite loop, since you will see the special element again&lt;/ins&gt;.&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# Let&amp;#039;s do something natural. Make it possible to add one FastaInstance to another using the &amp;#039;&amp;#039;&amp;#039;+=&amp;#039;&amp;#039;&amp;#039; operator, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance1 += FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The headers and sequences in Fastainstance2 should be added (list extension) to the headers and sequences in FastaInstance1. Use the magic method [https://zetcode.com/python/dunder-iadd/ &amp;#039;&amp;#039;&amp;#039;__iadd__&amp;#039;&amp;#039;&amp;#039;]. Try with the files &amp;#039;&amp;#039;dna7.fsa&amp;#039;&amp;#039; and &amp;#039;&amp;#039;protein.fsa&amp;#039;&amp;#039;. That will be a strange DNA and protein mix, but it is a great opportunity to use the &amp;#039;&amp;#039;&amp;#039;discard&amp;#039;&amp;#039;&amp;#039; method to get rid of one of the types.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Let&amp;#039;s do something natural. Make it possible to add one FastaInstance to another using the &amp;#039;&amp;#039;&amp;#039;+=&amp;#039;&amp;#039;&amp;#039; operator, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance1 += FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The headers and sequences in Fastainstance2 should be added (list extension) to the headers and sequences in FastaInstance1. Use the magic method [https://zetcode.com/python/dunder-iadd/ &amp;#039;&amp;#039;&amp;#039;__iadd__&amp;#039;&amp;#039;&amp;#039;]. Try with the files &amp;#039;&amp;#039;dna7.fsa&amp;#039;&amp;#039; and &amp;#039;&amp;#039;protein.fsa&amp;#039;&amp;#039;. That will be a strange DNA and protein mix, but it is a great opportunity to use the &amp;#039;&amp;#039;&amp;#039;discard&amp;#039;&amp;#039;&amp;#039; method to get rid of one of the types.&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# Implement the &amp;#039;&amp;#039;addition&amp;#039;&amp;#039;, using [https://zetcode.com/python/dunder-add/ &amp;#039;&amp;#039;&amp;#039;__add__&amp;#039;&amp;#039;&amp;#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor. Now that the Fasta class is done, save it in a file, so you can import it for the next exercises.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Implement the &amp;#039;&amp;#039;addition&amp;#039;&amp;#039;, using [https://zetcode.com/python/dunder-add/ &amp;#039;&amp;#039;&amp;#039;__add__&amp;#039;&amp;#039;&amp;#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor. Now that the Fasta class is done, save it in a file, so you can import it for the next exercises.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=270&amp;oldid=prev</id>
		<title>WikiSysop: /* Required course material for the lesson */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=270&amp;oldid=prev"/>
		<updated>2026-03-19T16:00:12Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Required course material for the lesson&lt;/span&gt;&lt;/span&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 18:00, 19 March 2026&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-l6&quot;&gt;Line 6:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 6:&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;== Required course material for the lesson ==&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;== Required course material for the lesson ==&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;div&gt;Powerpoint: [https://teaching.healthtech.dtu.dk/material/22118/22118_07-Classes.ppt Classes]&amp;lt;br&amp;gt;&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;Powerpoint: [https://teaching.healthtech.dtu.dk/material/22118/22118_07-Classes.ppt Classes]&amp;lt;br&amp;gt;&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;Resource: [[Example code - &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Classes&lt;/del&gt;]]&amp;lt;br&amp;gt;&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;Resource: [[Example code - &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;Inheritance issues&lt;/ins&gt;]]&amp;lt;br&amp;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;== Subjects covered ==&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;== Subjects covered ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=269&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=269&amp;oldid=prev"/>
		<updated>2026-03-18T22:06:42Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&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 00:06, 19 March 2026&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-l21&quot;&gt;Line 21:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 21:&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;# Implement the &amp;#039;&amp;#039;addition&amp;#039;&amp;#039;, using [https://zetcode.com/python/dunder-add/ &amp;#039;&amp;#039;&amp;#039;__add__&amp;#039;&amp;#039;&amp;#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor. Now that the Fasta class is done, save it in a file, so you can import it for the next exercises.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Implement the &amp;#039;&amp;#039;addition&amp;#039;&amp;#039;, using [https://zetcode.com/python/dunder-add/ &amp;#039;&amp;#039;&amp;#039;__add__&amp;#039;&amp;#039;&amp;#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor. Now that the Fasta class is done, save it in a file, so you can import it for the next exercises.&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# You can consider a &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; instance as a &amp;#039;&amp;#039;set&amp;#039;&amp;#039; of headers/sequences. The sequences are obviously uniquely identified by the identifier in the header, which is what will be used as key in the set operations. In the rest of the exercises we will explore inheritance by making a new class called &amp;#039;&amp;#039;&amp;#039;FastaSet&amp;#039;&amp;#039;&amp;#039;, which inherits from the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class.&amp;lt;br&amp;gt;A) The original &amp;#039;&amp;#039;&amp;#039;__init__&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;save&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;load&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insert&amp;#039;&amp;#039;&amp;#039;, the iteration and the corresponding &amp;#039;&amp;#039;&amp;#039;deletethis&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis&amp;#039;&amp;#039;&amp;#039; methods are fine to keep in the new class (meaning do nothing about them).&amp;lt;br&amp;gt;B) To help in the new class create a new getter method &amp;#039;&amp;#039;&amp;#039;identifiers&amp;#039;&amp;#039;&amp;#039;, which returns a list of identifiers from the header lines.&amp;lt;br&amp;gt;C) Override the &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; method such that it takes a set or list of identifiers and returns only the headers/sequences that corresponds to the identifiers in the list. If you do not specify a list/set of identifiers, it still returns all.&amp;lt;br&amp;gt;D) Override the &amp;#039;&amp;#039;&amp;#039;delete&amp;#039;&amp;#039;&amp;#039; method in a similar way - it deletes the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;E) Override the &amp;#039;&amp;#039;&amp;#039;verify&amp;#039;&amp;#039;&amp;#039; method in a similar way to &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; - it verifies the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;F) Override the &amp;#039;&amp;#039;&amp;#039;discard&amp;#039;&amp;#039;&amp;#039; method in a similar way to &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; - it discards the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# You can consider a &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; instance as a &amp;#039;&amp;#039;set&amp;#039;&amp;#039; of headers/sequences. The sequences are obviously uniquely identified by the identifier in the header, which is what will be used as key in the set operations. In the rest of the exercises we will explore inheritance by making a new class called &amp;#039;&amp;#039;&amp;#039;FastaSet&amp;#039;&amp;#039;&amp;#039;, which inherits from the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class.&amp;lt;br&amp;gt;A) The original &amp;#039;&amp;#039;&amp;#039;__init__&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;save&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;load&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insert&amp;#039;&amp;#039;&amp;#039;, the iteration and the corresponding &amp;#039;&amp;#039;&amp;#039;deletethis&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis&amp;#039;&amp;#039;&amp;#039; methods are fine to keep in the new class (meaning do nothing about them).&amp;lt;br&amp;gt;B) To help in the new class create a new getter method &amp;#039;&amp;#039;&amp;#039;identifiers&amp;#039;&amp;#039;&amp;#039;, which returns a list of identifiers from the header lines.&amp;lt;br&amp;gt;C) Override the &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; method such that it takes a set or list of identifiers and returns only the headers/sequences that corresponds to the identifiers in the list. If you do not specify a list/set of identifiers, it still returns all.&amp;lt;br&amp;gt;D) Override the &amp;#039;&amp;#039;&amp;#039;delete&amp;#039;&amp;#039;&amp;#039; method in a similar way - it deletes the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;E) Override the &amp;#039;&amp;#039;&amp;#039;verify&amp;#039;&amp;#039;&amp;#039; method in a similar way to &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; - it verifies the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;F) Override the &amp;#039;&amp;#039;&amp;#039;discard&amp;#039;&amp;#039;&amp;#039; method in a similar way to &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; - it discards the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# As the new FastaSet class is set orientated, implement the following set operations in the class:&amp;lt;br&amp;gt;A) union, operator is &#039;&#039;&#039;|&#039;&#039;&#039;, magic method is &#039;&#039;&#039;__or__&#039;&#039;&#039;.&amp;lt;br&amp;gt;B) intersection, operator is &#039;&#039;&#039;&amp;amp;&#039;&#039;&#039;, magic method is &#039;&#039;&#039;__and__&#039;&#039;&#039;.&amp;lt;br&amp;gt;C) difference, operator is &#039;&#039;&#039;-&#039;&#039;&#039;, magic method is &#039;&#039;&#039;__sub__&#039;&#039;&#039;.&amp;lt;br&amp;gt;D) symmetric difference, operator is &#039;&#039;&#039;^&#039;&#039;&#039;, magic method is &#039;&#039;&#039;__xor__&#039;&#039;&#039;.&amp;lt;br&amp;gt;These are quite similar to the addition in exercise 4 - the operators are used in the same way and a new Fasta object is returned. The identity of the sequence depends on the identifier in the corresponding header. This is an example of operator overloading.&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;# As the new FastaSet class is set orientated, implement the following set operations in the class:&amp;lt;br&amp;gt;A) union, operator is &#039;&#039;&#039;|&#039;&#039;&#039;, magic method is &#039;&#039;&#039;__or__&#039;&#039;&#039;.&amp;lt;br&amp;gt;B) intersection, operator is &#039;&#039;&#039;&amp;amp;&#039;&#039;&#039;, magic method is &#039;&#039;&#039;__and__&#039;&#039;&#039;.&amp;lt;br&amp;gt;C) difference, operator is &#039;&#039;&#039;-&#039;&#039;&#039;, magic method is &#039;&#039;&#039;__sub__&#039;&#039;&#039;.&amp;lt;br&amp;gt;D) symmetric difference, operator is &#039;&#039;&#039;^&#039;&#039;&#039;, magic method is &#039;&#039;&#039;__xor__&#039;&#039;&#039;.&amp;lt;br&amp;gt;These are quite similar to the addition in exercise 4 - the operators are used in the same way and a new Fasta object is returned. The identity of the sequence depends on the identifier in the corresponding header. This is an example of operator overloading &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;- the normal arithmetic operator used on numbers are used on something completely different&lt;/ins&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;== Exercises for extra practice ==&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;== Exercises for extra practice ==&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;div&gt;# You continue to add the unique identifier control for all methods in Fasta and FastaSet, as mentioned last week.&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;# You continue to add the unique identifier control for all methods in Fasta and FastaSet, as mentioned last week.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=267&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=267&amp;oldid=prev"/>
		<updated>2026-03-18T16:47:37Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&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 18:47, 18 March 2026&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-l18&quot;&gt;Line 18:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 18:&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;# Use magic methods to add &amp;#039;&amp;#039;iteration&amp;#039;&amp;#039; and &amp;#039;&amp;#039;length&amp;#039;&amp;#039; evaluation (using &amp;#039;&amp;#039;&amp;#039;__iter__&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;__len__&amp;#039;&amp;#039;&amp;#039; magic methods) to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;The function &amp;#039;&amp;#039;&amp;#039;len&amp;#039;&amp;#039;&amp;#039; returns the number of sequences.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Use magic methods to add &amp;#039;&amp;#039;iteration&amp;#039;&amp;#039; and &amp;#039;&amp;#039;length&amp;#039;&amp;#039; evaluation (using &amp;#039;&amp;#039;&amp;#039;__iter__&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;__len__&amp;#039;&amp;#039;&amp;#039; magic methods) to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;The function &amp;#039;&amp;#039;&amp;#039;len&amp;#039;&amp;#039;&amp;#039; returns the number of sequences.&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# Add the methods &amp;#039;&amp;#039;&amp;#039;deletethis()&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis(header, sequence)&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis(alphabet)&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis(alphabet)&amp;#039;&amp;#039;&amp;#039; to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. The methods should only work when &amp;#039;&amp;#039;iterating over an instance at the current item&amp;#039;&amp;#039;, i.e. they work when you are iterating over the fasta sequences on the &amp;#039;&amp;#039;current&amp;#039;&amp;#039; sequence and header, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&amp;quot;DNA&amp;quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible. Hint: change the way your iteration works in the previous exercise. You need to take a position on this issue: When iterating over entries, how should you continue after inserting entries at your current position? Example: You are at element in position 5, you insert 2 elements at that position. This WILL mean the new elements are at position 5 and 6, and the one you &amp;quot;looked at&amp;quot; is now on position 7. Do you continue the iteration on position 5 or is the next position 8? My opinion is that you should not look at the new elements and you have already looked at the &amp;quot;old&amp;quot; element ant 5, so the next one is at 8. You are free to make your own decision - just be clear about it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Add the methods &amp;#039;&amp;#039;&amp;#039;deletethis()&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis(header, sequence)&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis(alphabet)&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis(alphabet)&amp;#039;&amp;#039;&amp;#039; to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. The methods should only work when &amp;#039;&amp;#039;iterating over an instance at the current item&amp;#039;&amp;#039;, i.e. they work when you are iterating over the fasta sequences on the &amp;#039;&amp;#039;current&amp;#039;&amp;#039; sequence and header, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&amp;quot;DNA&amp;quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible. Hint: change the way your iteration works in the previous exercise. You need to take a position on this issue: When iterating over entries, how should you continue after inserting entries at your current position? Example: You are at element in position 5, you insert 2 elements at that position. This WILL mean the new elements are at position 5 and 6, and the one you &amp;quot;looked at&amp;quot; is now on position 7. Do you continue the iteration on position 5 or is the next position 8? My opinion is that you should not look at the new elements and you have already looked at the &amp;quot;old&amp;quot; element ant 5, so the next one is at 8. You are free to make your own decision - just be clear about it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Let&#039;s do something natural. Make it possible to add one FastaInstance to another using the &#039;&#039;&#039;+=&#039;&#039;&#039; operator, like this:&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;FastaInstance1 += FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The headers and sequences in Fastainstance2 should be added (list extension) to the headers and sequences in FastaInstance1. Use the magic method [https://zetcode.com/python/dunder-iadd/ &#039;&#039;&#039;__iadd__&#039;&#039;&#039;].&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Let&#039;s do something natural. Make it possible to add one FastaInstance to another using the &#039;&#039;&#039;+=&#039;&#039;&#039; operator, like this:&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;FastaInstance1 += FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The headers and sequences in Fastainstance2 should be added (list extension) to the headers and sequences in FastaInstance1. Use the magic method [https://zetcode.com/python/dunder-iadd/ &#039;&#039;&#039;__iadd__&#039;&#039;&#039;]&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. Try with the files &#039;&#039;dna7.fsa&#039;&#039; and &#039;&#039;protein.fsa&#039;&#039;. That will be a strange DNA and protein mix, but it is a great opportunity to use the &#039;&#039;&#039;discard&#039;&#039;&#039; method to get rid of one of the types&lt;/ins&gt;.&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# Implement the &amp;#039;&amp;#039;addition&amp;#039;&amp;#039;, using [https://zetcode.com/python/dunder-add/ &amp;#039;&amp;#039;&amp;#039;__add__&amp;#039;&amp;#039;&amp;#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor. Now that the Fasta class is done, save it in a file, so you can import it for the next exercises.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Implement the &amp;#039;&amp;#039;addition&amp;#039;&amp;#039;, using [https://zetcode.com/python/dunder-add/ &amp;#039;&amp;#039;&amp;#039;__add__&amp;#039;&amp;#039;&amp;#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor. Now that the Fasta class is done, save it in a file, so you can import it for the next exercises.&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# You can consider a &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; instance as a &amp;#039;&amp;#039;set&amp;#039;&amp;#039; of headers/sequences. The sequences are obviously uniquely identified by the identifier in the header, which is what will be used as key in the set operations. In the rest of the exercises we will explore inheritance by making a new class called &amp;#039;&amp;#039;&amp;#039;FastaSet&amp;#039;&amp;#039;&amp;#039;, which inherits from the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class.&amp;lt;br&amp;gt;A) The original &amp;#039;&amp;#039;&amp;#039;__init__&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;save&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;load&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insert&amp;#039;&amp;#039;&amp;#039;, the iteration and the corresponding &amp;#039;&amp;#039;&amp;#039;deletethis&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis&amp;#039;&amp;#039;&amp;#039; methods are fine to keep in the new class (meaning do nothing about them).&amp;lt;br&amp;gt;B) To help in the new class create a new getter method &amp;#039;&amp;#039;&amp;#039;identifiers&amp;#039;&amp;#039;&amp;#039;, which returns a list of identifiers from the header lines.&amp;lt;br&amp;gt;C) Override the &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; method such that it takes a set or list of identifiers and returns only the headers/sequences that corresponds to the identifiers in the list. If you do not specify a list/set of identifiers, it still returns all.&amp;lt;br&amp;gt;D) Override the &amp;#039;&amp;#039;&amp;#039;delete&amp;#039;&amp;#039;&amp;#039; method in a similar way - it deletes the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;E) Override the &amp;#039;&amp;#039;&amp;#039;verify&amp;#039;&amp;#039;&amp;#039; method in a similar way to &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; - it verifies the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;F) Override the &amp;#039;&amp;#039;&amp;#039;discard&amp;#039;&amp;#039;&amp;#039; method in a similar way to &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; - it discards the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# You can consider a &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; instance as a &amp;#039;&amp;#039;set&amp;#039;&amp;#039; of headers/sequences. The sequences are obviously uniquely identified by the identifier in the header, which is what will be used as key in the set operations. In the rest of the exercises we will explore inheritance by making a new class called &amp;#039;&amp;#039;&amp;#039;FastaSet&amp;#039;&amp;#039;&amp;#039;, which inherits from the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class.&amp;lt;br&amp;gt;A) The original &amp;#039;&amp;#039;&amp;#039;__init__&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;save&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;load&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insert&amp;#039;&amp;#039;&amp;#039;, the iteration and the corresponding &amp;#039;&amp;#039;&amp;#039;deletethis&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis&amp;#039;&amp;#039;&amp;#039; methods are fine to keep in the new class (meaning do nothing about them).&amp;lt;br&amp;gt;B) To help in the new class create a new getter method &amp;#039;&amp;#039;&amp;#039;identifiers&amp;#039;&amp;#039;&amp;#039;, which returns a list of identifiers from the header lines.&amp;lt;br&amp;gt;C) Override the &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; method such that it takes a set or list of identifiers and returns only the headers/sequences that corresponds to the identifiers in the list. If you do not specify a list/set of identifiers, it still returns all.&amp;lt;br&amp;gt;D) Override the &amp;#039;&amp;#039;&amp;#039;delete&amp;#039;&amp;#039;&amp;#039; method in a similar way - it deletes the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;E) Override the &amp;#039;&amp;#039;&amp;#039;verify&amp;#039;&amp;#039;&amp;#039; method in a similar way to &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; - it verifies the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;F) Override the &amp;#039;&amp;#039;&amp;#039;discard&amp;#039;&amp;#039;&amp;#039; method in a similar way to &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; - it discards the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=265&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=265&amp;oldid=prev"/>
		<updated>2026-03-18T14:59:54Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&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:59, 18 March 2026&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-l17&quot;&gt;Line 17:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 17:&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 first four exercises will continue with the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class from last time.&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 first four exercises will continue with the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class from last time.&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;div&gt;# Use magic methods to add &amp;#039;&amp;#039;iteration&amp;#039;&amp;#039; and &amp;#039;&amp;#039;length&amp;#039;&amp;#039; evaluation (using &amp;#039;&amp;#039;&amp;#039;__iter__&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;__len__&amp;#039;&amp;#039;&amp;#039; magic methods) to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;The function &amp;#039;&amp;#039;&amp;#039;len&amp;#039;&amp;#039;&amp;#039; returns the number of sequences.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Use magic methods to add &amp;#039;&amp;#039;iteration&amp;#039;&amp;#039; and &amp;#039;&amp;#039;length&amp;#039;&amp;#039; evaluation (using &amp;#039;&amp;#039;&amp;#039;__iter__&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;__len__&amp;#039;&amp;#039;&amp;#039; magic methods) to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;The function &amp;#039;&amp;#039;&amp;#039;len&amp;#039;&amp;#039;&amp;#039; returns the number of sequences.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Add the methods &#039;&#039;&#039;deletethis()&#039;&#039;&#039;, &#039;&#039;&#039;insertthis(header, sequence)&#039;&#039;&#039;, &#039;&#039;&#039;verifythis(alphabet)&#039;&#039;&#039; and &#039;&#039;&#039;discardthis(alphabet)&#039;&#039;&#039; to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class. The methods should only work when &#039;&#039;iterating over an instance at the current item&#039;&#039;, i.e. they work when you are iterating over the fasta sequences on the &#039;&#039;current&#039;&#039; sequence and header, like this:&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&quot;DNA&quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible. Hint: change the way your iteration works in the previous exercise. You need to take a position on this issue: When &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;iteration &lt;/del&gt;over entries, how should you continue after inserting entries at your current position? Example: You are at element in position 5, you insert 2 elements at that position. This WILL mean the new elements are at position 5 and 6, and the one you &quot;looked at&quot; is now on position 7. Do you continue the iteration on position 5 or is the next position 8? My opinion is that you should not look at the new elements and you have already looked at the &quot;old&quot; element ant 5, so the next one is at 8. You are free to make your own decision - just be clear about it.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Add the methods &#039;&#039;&#039;deletethis()&#039;&#039;&#039;, &#039;&#039;&#039;insertthis(header, sequence)&#039;&#039;&#039;, &#039;&#039;&#039;verifythis(alphabet)&#039;&#039;&#039; and &#039;&#039;&#039;discardthis(alphabet)&#039;&#039;&#039; to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class. The methods should only work when &#039;&#039;iterating over an instance at the current item&#039;&#039;, i.e. they work when you are iterating over the fasta sequences on the &#039;&#039;current&#039;&#039; sequence and header, like this:&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&quot;DNA&quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible. Hint: change the way your iteration works in the previous exercise. You need to take a position on this issue: When &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;iterating &lt;/ins&gt;over entries, how should you continue after inserting entries at your current position? Example: You are at element in position 5, you insert 2 elements at that position. This WILL mean the new elements are at position 5 and 6, and the one you &quot;looked at&quot; is now on position 7. Do you continue the iteration on position 5 or is the next position 8? My opinion is that you should not look at the new elements and you have already looked at the &quot;old&quot; element ant 5, so the next one is at 8. You are free to make your own decision - just be clear about it.&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# Let&amp;#039;s do something natural. Make it possible to add one FastaInstance to another using the &amp;#039;&amp;#039;&amp;#039;+=&amp;#039;&amp;#039;&amp;#039; operator, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance1 += FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The headers and sequences in Fastainstance2 should be added (list extension) to the headers and sequences in FastaInstance1. Use the magic method [https://zetcode.com/python/dunder-iadd/ &amp;#039;&amp;#039;&amp;#039;__iadd__&amp;#039;&amp;#039;&amp;#039;].&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Let&amp;#039;s do something natural. Make it possible to add one FastaInstance to another using the &amp;#039;&amp;#039;&amp;#039;+=&amp;#039;&amp;#039;&amp;#039; operator, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance1 += FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The headers and sequences in Fastainstance2 should be added (list extension) to the headers and sequences in FastaInstance1. Use the magic method [https://zetcode.com/python/dunder-iadd/ &amp;#039;&amp;#039;&amp;#039;__iadd__&amp;#039;&amp;#039;&amp;#039;].&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# Implement the &amp;#039;&amp;#039;addition&amp;#039;&amp;#039;, using [https://zetcode.com/python/dunder-add/ &amp;#039;&amp;#039;&amp;#039;__add__&amp;#039;&amp;#039;&amp;#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor. Now that the Fasta class is done, save it in a file, so you can import it for the next exercises.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Implement the &amp;#039;&amp;#039;addition&amp;#039;&amp;#039;, using [https://zetcode.com/python/dunder-add/ &amp;#039;&amp;#039;&amp;#039;__add__&amp;#039;&amp;#039;&amp;#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor. Now that the Fasta class is done, save it in a file, so you can import it for the next exercises.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=264&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=264&amp;oldid=prev"/>
		<updated>2026-03-18T14:59:31Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&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:59, 18 March 2026&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-l17&quot;&gt;Line 17:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 17:&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 first four exercises will continue with the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class from last time.&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 first four exercises will continue with the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class from last time.&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;div&gt;# Use magic methods to add &amp;#039;&amp;#039;iteration&amp;#039;&amp;#039; and &amp;#039;&amp;#039;length&amp;#039;&amp;#039; evaluation (using &amp;#039;&amp;#039;&amp;#039;__iter__&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;__len__&amp;#039;&amp;#039;&amp;#039; magic methods) to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;The function &amp;#039;&amp;#039;&amp;#039;len&amp;#039;&amp;#039;&amp;#039; returns the number of sequences.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Use magic methods to add &amp;#039;&amp;#039;iteration&amp;#039;&amp;#039; and &amp;#039;&amp;#039;length&amp;#039;&amp;#039; evaluation (using &amp;#039;&amp;#039;&amp;#039;__iter__&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;__len__&amp;#039;&amp;#039;&amp;#039; magic methods) to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. Do this so you can write code like &amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;if len(MyFastaInstance) &amp;gt; 0:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;print(header, sequence)&amp;lt;/div&amp;gt;The function &amp;#039;&amp;#039;&amp;#039;len&amp;#039;&amp;#039;&amp;#039; returns the number of sequences.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Add the methods &#039;&#039;&#039;deletethis()&#039;&#039;&#039;, &#039;&#039;&#039;insertthis(header, sequence)&#039;&#039;&#039;, &#039;&#039;&#039;verifythis(alphabet)&#039;&#039;&#039; and &#039;&#039;&#039;discardthis(alphabet)&#039;&#039;&#039; to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class. The methods should only work when &#039;&#039;iterating over an instance at the current item&#039;&#039;, i.e. they work when you are iterating over the fasta sequences on the &#039;&#039;current&#039;&#039; sequence and header, like this:&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&quot;DNA&quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible. Hint: change the way your iteration works in the previous exercise.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Add the methods &#039;&#039;&#039;deletethis()&#039;&#039;&#039;, &#039;&#039;&#039;insertthis(header, sequence)&#039;&#039;&#039;, &#039;&#039;&#039;verifythis(alphabet)&#039;&#039;&#039; and &#039;&#039;&#039;discardthis(alphabet)&#039;&#039;&#039; to the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class. The methods should only work when &#039;&#039;iterating over an instance at the current item&#039;&#039;, i.e. they work when you are iterating over the fasta sequences on the &#039;&#039;current&#039;&#039; sequence and header, like this:&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&quot;DNA&quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible. Hint: change the way your iteration works in the previous exercise&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. You need to take a position on this issue: When iteration over entries, how should you continue after inserting entries at your current position? Example: You are at element in position 5, you insert 2 elements at that position. This WILL mean the new elements are at position 5 and 6, and the one you &quot;looked at&quot; is now on position 7. Do you continue the iteration on position 5 or is the next position 8? My opinion is that you should not look at the new elements and you have already looked at the &quot;old&quot; element ant 5, so the next one is at 8. You are free to make your own decision - just be clear about it&lt;/ins&gt;.&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# Let&amp;#039;s do something natural. Make it possible to add one FastaInstance to another using the &amp;#039;&amp;#039;&amp;#039;+=&amp;#039;&amp;#039;&amp;#039; operator, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance1 += FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The headers and sequences in Fastainstance2 should be added (list extension) to the headers and sequences in FastaInstance1. Use the magic method [https://zetcode.com/python/dunder-iadd/ &amp;#039;&amp;#039;&amp;#039;__iadd__&amp;#039;&amp;#039;&amp;#039;].&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Let&amp;#039;s do something natural. Make it possible to add one FastaInstance to another using the &amp;#039;&amp;#039;&amp;#039;+=&amp;#039;&amp;#039;&amp;#039; operator, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance1 += FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The headers and sequences in Fastainstance2 should be added (list extension) to the headers and sequences in FastaInstance1. Use the magic method [https://zetcode.com/python/dunder-iadd/ &amp;#039;&amp;#039;&amp;#039;__iadd__&amp;#039;&amp;#039;&amp;#039;].&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# Implement the &amp;#039;&amp;#039;addition&amp;#039;&amp;#039;, using [https://zetcode.com/python/dunder-add/ &amp;#039;&amp;#039;&amp;#039;__add__&amp;#039;&amp;#039;&amp;#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor. Now that the Fasta class is done, save it in a file, so you can import it for the next exercises.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Implement the &amp;#039;&amp;#039;addition&amp;#039;&amp;#039;, using [https://zetcode.com/python/dunder-add/ &amp;#039;&amp;#039;&amp;#039;__add__&amp;#039;&amp;#039;&amp;#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor. Now that the Fasta class is done, save it in a file, so you can import it for the next exercises.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=263&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises for extra practice */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=263&amp;oldid=prev"/>
		<updated>2026-03-18T09:06:30Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises for extra practice&lt;/span&gt;&lt;/span&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 11:06, 18 March 2026&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-l24&quot;&gt;Line 24:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 24:&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;== Exercises for extra practice ==&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;== Exercises for extra practice ==&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;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;# You continue to add the unique identifier control for all methods in Fasta and FastaSet, as mentioned last week.&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=259&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=259&amp;oldid=prev"/>
		<updated>2026-03-17T15:12:09Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&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 17:12, 17 March 2026&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-l19&quot;&gt;Line 19:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 19:&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;# Add the methods &amp;#039;&amp;#039;&amp;#039;deletethis()&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis(header, sequence)&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis(alphabet)&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis(alphabet)&amp;#039;&amp;#039;&amp;#039; to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. The methods should only work when &amp;#039;&amp;#039;iterating over an instance at the current item&amp;#039;&amp;#039;, i.e. they work when you are iterating over the fasta sequences on the &amp;#039;&amp;#039;current&amp;#039;&amp;#039; sequence and header, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&amp;quot;DNA&amp;quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible. Hint: change the way your iteration works in the previous exercise.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Add the methods &amp;#039;&amp;#039;&amp;#039;deletethis()&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis(header, sequence)&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis(alphabet)&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis(alphabet)&amp;#039;&amp;#039;&amp;#039; to the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class. The methods should only work when &amp;#039;&amp;#039;iterating over an instance at the current item&amp;#039;&amp;#039;, i.e. they work when you are iterating over the fasta sequences on the &amp;#039;&amp;#039;current&amp;#039;&amp;#039; sequence and header, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;for header, sequence in MyFastaInstance:&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;if not MyFastaInstance.verifythis(&amp;quot;DNA&amp;quot;):&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;MyFastaInstance.deletethis()&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;continue&amp;lt;br&amp;gt;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp;# Do something with header and sequence&amp;lt;/div&amp;gt;As some may remember, it is normally impossible to successfully iterate straightforward through a list and delete and/or add elements to the list during the iteration. You have to make this possible. Hint: change the way your iteration works in the previous exercise.&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# Let&amp;#039;s do something natural. Make it possible to add one FastaInstance to another using the &amp;#039;&amp;#039;&amp;#039;+=&amp;#039;&amp;#039;&amp;#039; operator, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance1 += FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The headers and sequences in Fastainstance2 should be added (list extension) to the headers and sequences in FastaInstance1. Use the magic method [https://zetcode.com/python/dunder-iadd/ &amp;#039;&amp;#039;&amp;#039;__iadd__&amp;#039;&amp;#039;&amp;#039;].&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Let&amp;#039;s do something natural. Make it possible to add one FastaInstance to another using the &amp;#039;&amp;#039;&amp;#039;+=&amp;#039;&amp;#039;&amp;#039; operator, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance1 += FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The headers and sequences in Fastainstance2 should be added (list extension) to the headers and sequences in FastaInstance1. Use the magic method [https://zetcode.com/python/dunder-iadd/ &amp;#039;&amp;#039;&amp;#039;__iadd__&amp;#039;&amp;#039;&amp;#039;].&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Implement the &#039;&#039;addition&#039;&#039;, using [https://zetcode.com/python/dunder-add/ &#039;&#039;&#039;__add__&#039;&#039;&#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Implement the &#039;&#039;addition&#039;&#039;, using [https://zetcode.com/python/dunder-add/ &#039;&#039;&#039;__add__&#039;&#039;&#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&quot;font-family:&#039;Courier New&#039;&quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;. Now that the Fasta class is done, save it in a file, so you can import it for the next exercises&lt;/ins&gt;.&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# You can consider a &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; instance as a &amp;#039;&amp;#039;set&amp;#039;&amp;#039; of headers/sequences. The sequences are obviously uniquely identified by the identifier in the header, which is what will be used as key in the set operations. In the rest of the exercises we will explore inheritance by making a new class called &amp;#039;&amp;#039;&amp;#039;FastaSet&amp;#039;&amp;#039;&amp;#039;, which inherits from the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class.&amp;lt;br&amp;gt;A) The original &amp;#039;&amp;#039;&amp;#039;__init__&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;save&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;load&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insert&amp;#039;&amp;#039;&amp;#039;, the iteration and the corresponding &amp;#039;&amp;#039;&amp;#039;deletethis&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis&amp;#039;&amp;#039;&amp;#039; methods are fine to keep in the new class (meaning do nothing about them).&amp;lt;br&amp;gt;B) To help in the new class create a new getter method &amp;#039;&amp;#039;&amp;#039;identifiers&amp;#039;&amp;#039;&amp;#039;, which returns a list of identifiers from the header lines.&amp;lt;br&amp;gt;C) Override the &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; method such that it takes a set or list of identifiers and returns only the headers/sequences that corresponds to the identifiers in the list. If you do not specify a list/set of identifiers, it still returns all.&amp;lt;br&amp;gt;D) Override the &amp;#039;&amp;#039;&amp;#039;delete&amp;#039;&amp;#039;&amp;#039; method in a similar way - it deletes the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;E) Override the &amp;#039;&amp;#039;&amp;#039;verify&amp;#039;&amp;#039;&amp;#039; method in a similar way to &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; - it verifies the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;F) Override the &amp;#039;&amp;#039;&amp;#039;discard&amp;#039;&amp;#039;&amp;#039; method in a similar way to &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; - it discards the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# You can consider a &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; instance as a &amp;#039;&amp;#039;set&amp;#039;&amp;#039; of headers/sequences. The sequences are obviously uniquely identified by the identifier in the header, which is what will be used as key in the set operations. In the rest of the exercises we will explore inheritance by making a new class called &amp;#039;&amp;#039;&amp;#039;FastaSet&amp;#039;&amp;#039;&amp;#039;, which inherits from the &amp;#039;&amp;#039;&amp;#039;Fasta&amp;#039;&amp;#039;&amp;#039; class.&amp;lt;br&amp;gt;A) The original &amp;#039;&amp;#039;&amp;#039;__init__&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;save&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;load&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insert&amp;#039;&amp;#039;&amp;#039;, the iteration and the corresponding &amp;#039;&amp;#039;&amp;#039;deletethis&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;insertthis&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;verifythis&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;discardthis&amp;#039;&amp;#039;&amp;#039; methods are fine to keep in the new class (meaning do nothing about them).&amp;lt;br&amp;gt;B) To help in the new class create a new getter method &amp;#039;&amp;#039;&amp;#039;identifiers&amp;#039;&amp;#039;&amp;#039;, which returns a list of identifiers from the header lines.&amp;lt;br&amp;gt;C) Override the &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; method such that it takes a set or list of identifiers and returns only the headers/sequences that corresponds to the identifiers in the list. If you do not specify a list/set of identifiers, it still returns all.&amp;lt;br&amp;gt;D) Override the &amp;#039;&amp;#039;&amp;#039;delete&amp;#039;&amp;#039;&amp;#039; method in a similar way - it deletes the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;E) Override the &amp;#039;&amp;#039;&amp;#039;verify&amp;#039;&amp;#039;&amp;#039; method in a similar way to &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; - it verifies the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;F) Override the &amp;#039;&amp;#039;&amp;#039;discard&amp;#039;&amp;#039;&amp;#039; method in a similar way to &amp;#039;&amp;#039;&amp;#039;content&amp;#039;&amp;#039;&amp;#039; - it discards the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# As the new FastaSet class is set orientated, implement the following set operations in the class:&amp;lt;br&amp;gt;A) union, operator is &amp;#039;&amp;#039;&amp;#039;|&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__or__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;B) intersection, operator is &amp;#039;&amp;#039;&amp;#039;&amp;amp;&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__and__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;C) difference, operator is &amp;#039;&amp;#039;&amp;#039;-&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__sub__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;D) symmetric difference, operator is &amp;#039;&amp;#039;&amp;#039;^&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__xor__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;These are quite similar to the addition in exercise 4 - the operators are used in the same way and a new Fasta object is returned. The identity of the sequence depends on the identifier in the corresponding header. This is an example of operator overloading.&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 the new FastaSet class is set orientated, implement the following set operations in the class:&amp;lt;br&amp;gt;A) union, operator is &amp;#039;&amp;#039;&amp;#039;|&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__or__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;B) intersection, operator is &amp;#039;&amp;#039;&amp;#039;&amp;amp;&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__and__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;C) difference, operator is &amp;#039;&amp;#039;&amp;#039;-&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__sub__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;D) symmetric difference, operator is &amp;#039;&amp;#039;&amp;#039;^&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__xor__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;These are quite similar to the addition in exercise 4 - the operators are used in the same way and a new Fasta object is returned. The identity of the sequence depends on the identifier in the corresponding header. This is an example of operator overloading.&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;== Exercises for extra practice ==&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;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
	<entry>
		<id>https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=258&amp;oldid=prev</id>
		<title>WikiSysop: /* Exercises to be handed in */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22118/index.php?title=Intermediate_classes&amp;diff=258&amp;oldid=prev"/>
		<updated>2026-03-17T15:08:27Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Exercises to be handed in&lt;/span&gt;&lt;/span&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 17:08, 17 March 2026&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-l20&quot;&gt;Line 20:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 20:&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;# Let&amp;#039;s do something natural. Make it possible to add one FastaInstance to another using the &amp;#039;&amp;#039;&amp;#039;+=&amp;#039;&amp;#039;&amp;#039; operator, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance1 += FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The headers and sequences in Fastainstance2 should be added (list extension) to the headers and sequences in FastaInstance1. Use the magic method [https://zetcode.com/python/dunder-iadd/ &amp;#039;&amp;#039;&amp;#039;__iadd__&amp;#039;&amp;#039;&amp;#039;].&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Let&amp;#039;s do something natural. Make it possible to add one FastaInstance to another using the &amp;#039;&amp;#039;&amp;#039;+=&amp;#039;&amp;#039;&amp;#039; operator, like this:&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance1 += FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The headers and sequences in Fastainstance2 should be added (list extension) to the headers and sequences in FastaInstance1. Use the magic method [https://zetcode.com/python/dunder-iadd/ &amp;#039;&amp;#039;&amp;#039;__iadd__&amp;#039;&amp;#039;&amp;#039;].&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# Implement the &amp;#039;&amp;#039;addition&amp;#039;&amp;#039;, using [https://zetcode.com/python/dunder-add/ &amp;#039;&amp;#039;&amp;#039;__add__&amp;#039;&amp;#039;&amp;#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# Implement the &amp;#039;&amp;#039;addition&amp;#039;&amp;#039;, using [https://zetcode.com/python/dunder-add/ &amp;#039;&amp;#039;&amp;#039;__add__&amp;#039;&amp;#039;&amp;#039;]. Addition creates a new Fasta instance, but leaves the originals untouched.&amp;lt;div style=&amp;quot;font-family:&amp;#039;Courier New&amp;#039;&amp;quot;&amp;gt;FastaInstance3 = FastaInstance1 + FastaInstance2&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;The resulting Fasta object must contain the headers and sequences from FastaInstance1 and FastaInstance2 in that order. Note that this works as an alternative constructor.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# You can consider a &#039;&#039;&#039;Fasta&#039;&#039;&#039; instance as a &#039;&#039;set&#039;&#039; of headers/sequences. The sequences are obviously uniquely identified by the identifier in the header, which is what will be used as key in the set operations. In the rest of the exercises we will explore inheritance by making a new class called &#039;&#039;&#039;FastaSet&#039;&#039;&#039;, which inherits from the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class.&amp;lt;br&amp;gt;A) The original &#039;&#039;&#039;__init__&#039;&#039;&#039;, &#039;&#039;&#039;save&#039;&#039;&#039;, &#039;&#039;&#039;load&#039;&#039;&#039;, &#039;&#039;&#039;insert&#039;&#039;&#039;, the iteration and the corresponding &#039;&#039;&#039;deletethis&#039;&#039;&#039;, &#039;&#039;&#039;insertthis&#039;&#039;&#039;, &#039;&#039;&#039;verifythis&#039;&#039;&#039; and &#039;&#039;&#039;discardthis&#039;&#039;&#039; methods are fine to keep in the new class (meaning do nothing about them).&amp;lt;br&amp;gt;B) To help in the new class create a new getter method &#039;&#039;&#039;identifiers&#039;&#039;&#039;, which returns a list of identifiers from the header lines.&amp;lt;br&amp;gt;C) Override the &#039;&#039;&#039;content&#039;&#039;&#039; method such that it takes a set or list of identifiers and returns only the headers/sequences that corresponds to the identifiers in the list. If you do not specify a list/set of identifiers, it still returns all.&amp;lt;br&amp;gt;D) Override the &#039;&#039;&#039;delete&#039;&#039;&#039; method in a similar way - it deletes the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;E) Override the &#039;&#039;&#039;verify&#039;&#039;&#039; method in a similar way to &#039;&#039;&#039;content&#039;&#039;&#039;.&amp;lt;br&amp;gt;F) Override the &#039;&#039;&#039;discard&#039;&#039;&#039; method in a similar way to &#039;&#039;&#039;content&#039;&#039;&#039;.&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&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;# You can consider a &#039;&#039;&#039;Fasta&#039;&#039;&#039; instance as a &#039;&#039;set&#039;&#039; of headers/sequences. The sequences are obviously uniquely identified by the identifier in the header, which is what will be used as key in the set operations. In the rest of the exercises we will explore inheritance by making a new class called &#039;&#039;&#039;FastaSet&#039;&#039;&#039;, which inherits from the &#039;&#039;&#039;Fasta&#039;&#039;&#039; class.&amp;lt;br&amp;gt;A) The original &#039;&#039;&#039;__init__&#039;&#039;&#039;, &#039;&#039;&#039;save&#039;&#039;&#039;, &#039;&#039;&#039;load&#039;&#039;&#039;, &#039;&#039;&#039;insert&#039;&#039;&#039;, the iteration and the corresponding &#039;&#039;&#039;deletethis&#039;&#039;&#039;, &#039;&#039;&#039;insertthis&#039;&#039;&#039;, &#039;&#039;&#039;verifythis&#039;&#039;&#039; and &#039;&#039;&#039;discardthis&#039;&#039;&#039; methods are fine to keep in the new class (meaning do nothing about them).&amp;lt;br&amp;gt;B) To help in the new class create a new getter method &#039;&#039;&#039;identifiers&#039;&#039;&#039;, which returns a list of identifiers from the header lines.&amp;lt;br&amp;gt;C) Override the &#039;&#039;&#039;content&#039;&#039;&#039; method such that it takes a set or list of identifiers and returns only the headers/sequences that corresponds to the identifiers in the list. If you do not specify a list/set of identifiers, it still returns all.&amp;lt;br&amp;gt;D) Override the &#039;&#039;&#039;delete&#039;&#039;&#039; method in a similar way - it deletes the headers/sequences that corresponds to the input.&amp;lt;br&amp;gt;E) Override the &#039;&#039;&#039;verify&#039;&#039;&#039; method in a similar way to &#039;&#039;&#039;content&#039;&#039;&#039; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;- it verifies the headers/sequences that corresponds to the input&lt;/ins&gt;.&amp;lt;br&amp;gt;F) Override the &#039;&#039;&#039;discard&#039;&#039;&#039; method in a similar way to &#039;&#039;&#039;content&#039;&#039;&#039; &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;- it discards the headers/sequences that corresponds to the input&lt;/ins&gt;.&amp;lt;br&amp;gt;&amp;lt;br&amp;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;div&gt;# As the new FastaSet class is set orientated, implement the following set operations in the class:&amp;lt;br&amp;gt;A) union, operator is &amp;#039;&amp;#039;&amp;#039;|&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__or__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;B) intersection, operator is &amp;#039;&amp;#039;&amp;#039;&amp;amp;&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__and__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;C) difference, operator is &amp;#039;&amp;#039;&amp;#039;-&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__sub__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;D) symmetric difference, operator is &amp;#039;&amp;#039;&amp;#039;^&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__xor__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;These are quite similar to the addition in exercise 4 - the operators are used in the same way and a new Fasta object is returned. The identity of the sequence depends on the identifier in the corresponding header. This is an example of operator overloading.&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 the new FastaSet class is set orientated, implement the following set operations in the class:&amp;lt;br&amp;gt;A) union, operator is &amp;#039;&amp;#039;&amp;#039;|&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__or__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;B) intersection, operator is &amp;#039;&amp;#039;&amp;#039;&amp;amp;&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__and__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;C) difference, operator is &amp;#039;&amp;#039;&amp;#039;-&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__sub__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;D) symmetric difference, operator is &amp;#039;&amp;#039;&amp;#039;^&amp;#039;&amp;#039;&amp;#039;, magic method is &amp;#039;&amp;#039;&amp;#039;__xor__&amp;#039;&amp;#039;&amp;#039;.&amp;lt;br&amp;gt;These are quite similar to the addition in exercise 4 - the operators are used in the same way and a new Fasta object is returned. The identity of the sequence depends on the identifier in the corresponding header. This is an example of operator overloading.&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;== Exercises for extra practice ==&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;== Exercises for extra practice ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>