<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk:443/22101/index.php?action=history&amp;feed=atom&amp;title=More_with_Lists</id>
	<title>More with Lists - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?action=history&amp;feed=atom&amp;title=More_with_Lists"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=More_with_Lists&amp;action=history"/>
	<updated>2026-05-02T10:26:58Z</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/22101/index.php?title=More_with_Lists&amp;diff=80&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/22101/index.php?title=More_with_Lists&amp;diff=80&amp;oldid=prev"/>
		<updated>2024-10-30T10:02:45Z</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:02, 30 October 2024&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-l22&quot;&gt;Line 22:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 22:&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;# Make a program that reads all the words in the file &amp;#039;&amp;#039;words.txt&amp;#039;&amp;#039; into an list. First the words must be sorted alphabetically, then the list should be reversed (the first word shall be the last and vice versa), finally the resulting list should be written in &amp;#039;&amp;#039;words.txt&amp;#039;&amp;#039; - one word per line - the file is being overwritten.&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;# Make a program that reads all the words in the file &amp;#039;&amp;#039;words.txt&amp;#039;&amp;#039; into an list. First the words must be sorted alphabetically, then the list should be reversed (the first word shall be the last and vice versa), finally the resulting list should be written in &amp;#039;&amp;#039;words.txt&amp;#039;&amp;#039; - one word per line - the file is being overwritten.&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;# After having looked at the cleaned accession numbers in &amp;#039;&amp;#039;clean5.acc&amp;#039;&amp;#039;, you will have seen that the accession numbers are sorted. This means that you can use the much more powerful binary search method when searching for accession numbers. Repeat exercise 3 from last week, but this time use binary search instead of the linear search you did then. See what Wikipedia has to say about [http://en.wikipedia.org/wiki/Binary_search binary search]. Binary search as a method is well described in the solution to the &amp;quot;guess a number&amp;quot; exercise.&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;# After having looked at the cleaned accession numbers in &amp;#039;&amp;#039;clean5.acc&amp;#039;&amp;#039;, you will have seen that the accession numbers are sorted. This means that you can use the much more powerful binary search method when searching for accession numbers. Repeat exercise 3 from last week, but this time use binary search instead of the linear search you did then. See what Wikipedia has to say about [http://en.wikipedia.org/wiki/Binary_search binary search]. Binary search as a method is well described in the solution to the &amp;quot;guess a number&amp;quot; exercise.&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;# Calculate the three sums of the three columns in one reading of the file &#039;&#039;ex1.dat&#039;&#039; using &#039;&#039;&#039;split&#039;&#039;&#039; to separate the columns.&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;# Calculate the three sums of the three columns in one reading of the file &#039;&#039;ex1.dat&#039;&#039; using &#039;&#039;&#039;split&#039;&#039;&#039; to separate the columns. &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;The sums of the three columns are: -904.4143, 482.8410, 292.0515&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;div&gt;# Improve on the previous exercise by making a program that calculates the sum of all columns in the file, no matter how many columns there are. Each column should be summed individually. You can assume that each row (line) has the same number of columns in the file.&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;# Improve on the previous exercise by making a program that calculates the sum of all columns in the file, no matter how many columns there are. Each column should be summed individually. You can assume that each row (line) has the same number of columns in the file.&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;# &amp;lt;font color=&amp;quot;#AA00FF&amp;quot;&amp;gt;Make a Python program that can select specific columns from a column based (tab separated) file and save them in a new file. It should select the columns that you specify in the order you specify. Ask for input and output file names and column numbers (3 questions, example &amp;quot;ex1.dat&amp;quot;, &amp;quot;2col.acc&amp;quot; &amp;amp; &amp;quot;3 1&amp;quot;). The program should work with any number of columns in the input file.&amp;lt;/font&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;# &amp;lt;font color=&amp;quot;#AA00FF&amp;quot;&amp;gt;Make a Python program that can select specific columns from a column based (tab separated) file and save them in a new file. It should select the columns that you specify in the order you specify. Ask for input and output file names and column numbers (3 questions, example &amp;quot;ex1.dat&amp;quot;, &amp;quot;2col.acc&amp;quot; &amp;amp; &amp;quot;3 1&amp;quot;). The program should work with any number of columns in the input file.&amp;lt;/font&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/22101/index.php?title=More_with_Lists&amp;diff=31&amp;oldid=prev</id>
		<title>WikiSysop: Created page with &quot;__NOTOC__ {| width=500  style=&quot;float:right; margin-left: 10px; margin-top: -56px;&quot; |Previous: Lists/Sequences |Next: Simple Pattern Matching |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22101/22101_10-MoreLists.ppt More with Lists]&lt;br&gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=b253adf9-282f-4885-9ce3-af27012d346e More advanced methods with lists]&lt;br&gt; Video: [https://panopto.dtu.dk/Pano...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22101/index.php?title=More_with_Lists&amp;diff=31&amp;oldid=prev"/>
		<updated>2024-03-01T15:59:23Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;__NOTOC__ {| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot; |Previous: &lt;a href=&quot;/22101/index.php/Lists/Sequences&quot; title=&quot;Lists/Sequences&quot;&gt;Lists/Sequences&lt;/a&gt; |Next: &lt;a href=&quot;/22101/index.php/Simple_Pattern_Matching&quot; title=&quot;Simple Pattern Matching&quot;&gt;Simple Pattern Matching&lt;/a&gt; |} == Required course material for the lesson == Powerpoint: [https://teaching.healthtech.dtu.dk/material/22101/22101_10-MoreLists.ppt More with Lists]&amp;lt;br&amp;gt; Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=b253adf9-282f-4885-9ce3-af27012d346e More advanced methods with lists]&amp;lt;br&amp;gt; Video: [https://panopto.dtu.dk/Pano...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;__NOTOC__&lt;br /&gt;
{| width=500  style=&amp;quot;float:right; margin-left: 10px; margin-top: -56px;&amp;quot;&lt;br /&gt;
|Previous: [[Lists/Sequences]]&lt;br /&gt;
|Next: [[Simple Pattern Matching]]&lt;br /&gt;
|}&lt;br /&gt;
== Required course material for the lesson ==&lt;br /&gt;
Powerpoint: [https://teaching.healthtech.dtu.dk/material/22101/22101_10-MoreLists.ppt More with Lists]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=b253adf9-282f-4885-9ce3-af27012d346e More advanced methods with lists]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=9ed4e00e-ed19-4511-af51-af27012d11e5 Miscellaneous list concepts and workings]&amp;lt;br&amp;gt;&lt;br /&gt;
Resource: [[Example code - Lists]]&amp;lt;br&amp;gt;&lt;br /&gt;
Video: [https://panopto.dtu.dk/Panopto/Pages/Viewer.aspx?id=0d134a6c-ec9b-46d0-8a62-af27012bf0ef Live Coding]&lt;br /&gt;
&lt;br /&gt;
== Subjects covered ==&lt;br /&gt;
Lists and sequences and some methods that operate on lists;&amp;lt;br&amp;gt;&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;sort&amp;#039;&amp;#039;&amp;#039;, which surprisingly sorts the list according to some principle,&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;reverse&amp;#039;&amp;#039;&amp;#039;, which reverses a list,&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;split&amp;#039;&amp;#039;&amp;#039;, which splits a sting into a list.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;join&amp;#039;&amp;#039;&amp;#039;, which concatenates a list into a string.&lt;br /&gt;
&lt;br /&gt;
== Exercises to be handed in ==&lt;br /&gt;
# Similar to the first exercise last week, make a program that takes the words you input and saves them in the &amp;#039;&amp;#039;words.txt&amp;#039;&amp;#039; file. The difference is that this time there may be several words on the input line, not just one. The output is still one word per output line.&lt;br /&gt;
# Make a program that reads all the words in the file &amp;#039;&amp;#039;words.txt&amp;#039;&amp;#039; into an list. First the words must be sorted alphabetically, then the list should be reversed (the first word shall be the last and vice versa), finally the resulting list should be written in &amp;#039;&amp;#039;words.txt&amp;#039;&amp;#039; - one word per line - the file is being overwritten.&lt;br /&gt;
# After having looked at the cleaned accession numbers in &amp;#039;&amp;#039;clean5.acc&amp;#039;&amp;#039;, you will have seen that the accession numbers are sorted. This means that you can use the much more powerful binary search method when searching for accession numbers. Repeat exercise 3 from last week, but this time use binary search instead of the linear search you did then. See what Wikipedia has to say about [http://en.wikipedia.org/wiki/Binary_search binary search]. Binary search as a method is well described in the solution to the &amp;quot;guess a number&amp;quot; exercise.&lt;br /&gt;
# Calculate the three sums of the three columns in one reading of the file &amp;#039;&amp;#039;ex1.dat&amp;#039;&amp;#039; using &amp;#039;&amp;#039;&amp;#039;split&amp;#039;&amp;#039;&amp;#039; to separate the columns.&lt;br /&gt;
# Improve on the previous exercise by making a program that calculates the sum of all columns in the file, no matter how many columns there are. Each column should be summed individually. You can assume that each row (line) has the same number of columns in the file.&lt;br /&gt;
# &amp;lt;font color=&amp;quot;#AA00FF&amp;quot;&amp;gt;Make a Python program that can select specific columns from a column based (tab separated) file and save them in a new file. It should select the columns that you specify in the order you specify. Ask for input and output file names and column numbers (3 questions, example &amp;quot;ex1.dat&amp;quot;, &amp;quot;2col.acc&amp;quot; &amp;amp; &amp;quot;3 1&amp;quot;). The program should work with any number of columns in the input file.&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Exercises for extra practice ==&lt;br /&gt;
You will program a [https://en.wikipedia.org/wiki/Reverse_Polish_notation reverse polish notation] calculator. This is somewhat complicated, so I will split up the job in a number of smaller exercises, where the one exercise builds on the previous. Shortly, reverse polish notation is a mathematical notation in which operators follow their operands, i.e. adding two numbers is written by &amp;quot;3 4 +&amp;quot; instead of &amp;quot;3 + 4&amp;quot;. We will utilize a [https://en.wikipedia.org/wiki/Stack_(abstract_data_type) stack], which is simply a list, where elements are added to and removed from the bottom.&lt;br /&gt;
* Let&amp;#039;s start with making the overall structure; a loop that asks for input, which is one item/command at a time. Inside the loop, there can be a number of operations depending on the input. If you enter a number, it should be simply appended to your list (the stack, which is the word I will use in the rest of the exercises here). If you enter commands &amp;#039;&amp;#039;&amp;#039;STOP&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;EXIT&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;QUIT&amp;#039;&amp;#039;&amp;#039;, the loop should end and the program stop. If you enter something that the program does not understand it should write &amp;quot;Illegal command&amp;quot;, but otherwise do nothing.&lt;br /&gt;
* Add the following commands: &amp;#039;&amp;#039;&amp;#039;PEEK&amp;#039;&amp;#039;&amp;#039;, which displays the last number in the stack, and &amp;#039;&amp;#039;&amp;#039;SHOW&amp;#039;&amp;#039;&amp;#039; which will display the entire stack.&lt;br /&gt;
* Add the standard math operations, &amp;#039;&amp;#039;&amp;#039;+&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;-&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;*&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;/&amp;#039;&amp;#039;&amp;#039;: These remove 2 numbers from the stack (the last number in stack is the first operand and the second last number is the second operand), perform the operation and appends the result back to the stack. You notice operand order matters for - and /. At this point we have a simple but functional calculator.&lt;br /&gt;
* Add single number operations &amp;#039;&amp;#039;&amp;#039;LOG&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;SQRT&amp;#039;&amp;#039;&amp;#039;, which replaces the last number in the stack with the log/square root of the number.&lt;br /&gt;
* Solidify your program by ensuring any operations first check if the required number of operands are on the stack before trying to perform the operation. Display &amp;quot;Not enough operands on the stack&amp;quot; and otherwise do nothing if the check fails. Hint: Maybe lists of zero, one and two operands commands could be useful.&lt;br /&gt;
* Add the commands: &amp;#039;&amp;#039;&amp;#039;DROP&amp;#039;&amp;#039;&amp;#039; which simply removes the last number on the stack, &amp;#039;&amp;#039;&amp;#039;=&amp;#039;&amp;#039;&amp;#039;, which removes the last number on the stack and displays it, &amp;#039;&amp;#039;&amp;#039;SWITCH&amp;#039;&amp;#039;&amp;#039;, which switches the last two numbers on the stack, and &amp;#039;&amp;#039;&amp;#039;DUP&amp;#039;&amp;#039;&amp;#039; which duplicates the last number on the stack, i.e stack consists of 1, after DUP it consists of 1 1.&lt;br /&gt;
* Add the commands: &amp;#039;&amp;#039;&amp;#039;ABS&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;NEG&amp;#039;&amp;#039;&amp;#039; which replaces the last number on the stack which the absolute/negative value of the number.&lt;br /&gt;
* At this point you can probably work out some mathematical operations to add that require one or 2 operands by yourself. I can think of the &amp;#039;&amp;#039;&amp;#039;SIN&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;COS&amp;#039;&amp;#039;&amp;#039; &amp;amp; &amp;#039;&amp;#039;&amp;#039;TAN&amp;#039;&amp;#039;&amp;#039; operations, the &amp;#039;&amp;#039;&amp;#039;INT&amp;#039;&amp;#039;&amp;#039; taking the integer part of a number, &amp;#039;&amp;#039;&amp;#039;EXP&amp;#039;&amp;#039;&amp;#039;onential and &amp;#039;&amp;#039;&amp;#039;SQUARE&amp;#039;&amp;#039;&amp;#039;. Modulo operation with &amp;#039;&amp;#039;&amp;#039;%&amp;#039;&amp;#039;&amp;#039;. &amp;#039;&amp;#039;&amp;#039;FAC&amp;#039;&amp;#039;&amp;#039;torial. You could add constants like &amp;#039;&amp;#039;&amp;#039;PI&amp;#039;&amp;#039;&amp;#039; and &amp;#039;&amp;#039;&amp;#039;E&amp;#039;&amp;#039;&amp;#039; that simply puts an appropriate value on the stack.&lt;br /&gt;
* Add stack control with &amp;#039;&amp;#039;&amp;#039;CLEAR&amp;#039;&amp;#039;&amp;#039; to empty the stack and extend the &amp;#039;&amp;#039;&amp;#039;SWITCH&amp;#039;&amp;#039;&amp;#039; to switch the numbers as two given position like &amp;quot;SWITCH 2 4&amp;quot; if given positions.&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>