<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://teaching.healthtech.dtu.dk:443/22116/index.php?action=history&amp;feed=atom&amp;title=Example_code_-_Complex_data</id>
	<title>Example code - Complex data - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://teaching.healthtech.dtu.dk:443/22116/index.php?action=history&amp;feed=atom&amp;title=Example_code_-_Complex_data"/>
	<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22116/index.php?title=Example_code_-_Complex_data&amp;action=history"/>
	<updated>2026-04-22T23:45:32Z</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/22116/index.php?title=Example_code_-_Complex_data&amp;diff=250&amp;oldid=prev</id>
		<title>WikiSysop: /* Files used in example */</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22116/index.php?title=Example_code_-_Complex_data&amp;diff=250&amp;oldid=prev"/>
		<updated>2025-10-03T10:00:55Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Files used in example&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:00, 3 October 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Files used in example ==&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;== Files used in example ==&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;[http://teaching.healthtech.dtu.dk/material/&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;22113&lt;/del&gt;/TA_list.txt TA_list.txt]&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;[http://teaching.healthtech.dtu.dk/material/&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;22116&lt;/ins&gt;/TA_list.txt TA_list.txt]&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;[http://teaching.healthtech.dtu.dk/material/&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;22113&lt;/del&gt;/student_list.txt student_list.txt]&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;[http://teaching.healthtech.dtu.dk/material/&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;22116&lt;/ins&gt;/student_list.txt student_list.txt]&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;== Assigning students to TA&amp;#039;s, Take 1 ==&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;== Assigning students to TA&amp;#039;s, Take 1 ==&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/22116/index.php?title=Example_code_-_Complex_data&amp;diff=249&amp;oldid=prev</id>
		<title>WikiSysop: Created page with &quot;== Files used in example == [http://teaching.healthtech.dtu.dk/material/22113/TA_list.txt TA_list.txt]&lt;br&gt; [http://teaching.healthtech.dtu.dk/material/22113/student_list.txt student_list.txt]&lt;br&gt;  == Assigning students to TA&#039;s, Take 1 == This is a python3 program written by a TA. It was done in a hurry, without much regard to the teaching principles. The purpose of the program is to read a list of students and a list of TA&#039;s and randomly assign students to TA&#039;s for gradi...&quot;</title>
		<link rel="alternate" type="text/html" href="https://teaching.healthtech.dtu.dk:443/22116/index.php?title=Example_code_-_Complex_data&amp;diff=249&amp;oldid=prev"/>
		<updated>2025-10-03T09:58:26Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== Files used in example == [http://teaching.healthtech.dtu.dk/material/22113/TA_list.txt TA_list.txt]&amp;lt;br&amp;gt; [http://teaching.healthtech.dtu.dk/material/22113/student_list.txt student_list.txt]&amp;lt;br&amp;gt;  == Assigning students to TA&amp;#039;s, Take 1 == This is a python3 program written by a TA. It was done in a hurry, without much regard to the teaching principles. The purpose of the program is to read a list of students and a list of TA&amp;#039;s and randomly assign students to TA&amp;#039;s for gradi...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Files used in example ==&lt;br /&gt;
[http://teaching.healthtech.dtu.dk/material/22113/TA_list.txt TA_list.txt]&amp;lt;br&amp;gt;&lt;br /&gt;
[http://teaching.healthtech.dtu.dk/material/22113/student_list.txt student_list.txt]&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Assigning students to TA&amp;#039;s, Take 1 ==&lt;br /&gt;
This is a python3 program written by a TA. It was done in a hurry, without much regard to the teaching principles.&lt;br /&gt;
The purpose of the program is to read a list of students and a list of TA&amp;#039;s and randomly assign students to TA&amp;#039;s for grading.&lt;br /&gt;
&lt;br /&gt;
Some TA&amp;#039;s can take on fewer students than others, so there can be a quota. This must be taken into consideration. This is arranged by adding a number after the TA&amp;#039;s name in the tab-separated TA file. Also, students may sign up later or leave the course, so the program must be flexible enough to handle that. That can happen for the TA&amp;#039;s too. In both cases it is enough to either delete/add the TA/student or make a comment # in front of the name.&lt;br /&gt;
&lt;br /&gt;
The basic idea is to start from the top of the list of students and assign the student to the next TA in the TA list. When the bottom of the TA list is reached, start from the top once more, until all students are assigned. If a TA&amp;#039;s quota is filled, that TA is excluded. Since we don&amp;#039;t want the same student assigned to the same TA all the time, the student list is randomly shuffled using the random library. Since we want the load to be equal for TA&amp;#039;s (first TA in the list will always get most students, last will get least), the TA list is shuffled, too.&lt;br /&gt;
&lt;br /&gt;
The important data structure is TA_dict which is a dict of dict of list,&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
TA_dict = { &amp;#039;Peter&amp;#039;: { &amp;#039;max&amp;#039;: 10, &amp;#039;assigned&amp;#039;: [&amp;#039;Student A&amp;#039;, &amp;#039;Student F&amp;#039;, &amp;#039;Student K&amp;#039;] },&lt;br /&gt;
            &amp;#039;TA 1&amp;#039;:  { &amp;#039;max&amp;#039;:  5, &amp;#039;assigned&amp;#039;: [&amp;#039;Student B&amp;#039;, &amp;#039;Student G&amp;#039;, &amp;#039;Student L&amp;#039;] },&lt;br /&gt;
            &amp;#039;TA 2&amp;#039;:  { &amp;#039;max&amp;#039;: 10, &amp;#039;assigned&amp;#039;: [&amp;#039;Student C&amp;#039;, &amp;#039;Student H&amp;#039;, &amp;#039;Student M&amp;#039;] },&lt;br /&gt;
            &amp;#039;TA 3&amp;#039;:  { &amp;#039;max&amp;#039;:  5, &amp;#039;assigned&amp;#039;: [&amp;#039;Student D&amp;#039;, &amp;#039;Student I&amp;#039;, &amp;#039;Student N&amp;#039;] },&lt;br /&gt;
            &amp;#039;TA 4&amp;#039;:  { &amp;#039;max&amp;#039;: 10, &amp;#039;assigned&amp;#039;: [&amp;#039;Student E&amp;#039;, &amp;#039;Student J&amp;#039;, &amp;#039;Student O&amp;#039;] }&lt;br /&gt;
          }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/python3&lt;br /&gt;
import sys, random&lt;br /&gt;
&lt;br /&gt;
helpmessage = &amp;quot;usage:\nassign_TA.py\tlist of TAs\tlist of students\n\nThe list of TAs may contain a maximum of students to assign to the particular TA. This should be separated from the TA&amp;#039;s name by tab.\n&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#display help if requested or run without arguments&lt;br /&gt;
if len(sys.argv) &amp;lt; 3 or sys.argv[1] == &amp;#039;-h&amp;#039; or sys.argv[-1] == &amp;#039;--help&amp;#039;:&lt;br /&gt;
	sys.exit(helpmessage)&lt;br /&gt;
else:&lt;br /&gt;
	TA_file = sys.argv[1]&lt;br /&gt;
	student_file = sys.argv[2]&lt;br /&gt;
	&lt;br /&gt;
TA_dict = {}&lt;br /&gt;
TA_index = [] #list to serve as an index to the dict of dicts since dictionary keys are unordered.	&lt;br /&gt;
TA_IN = open(TA_file,&amp;#039;rt&amp;#039;, encoding=&amp;#039;utf8&amp;#039;)&lt;br /&gt;
for line in TA_IN:&lt;br /&gt;
	line = line.rstrip().split(&amp;#039;\t&amp;#039;)&lt;br /&gt;
	#if there is a second column this is the max value of students for that TA&lt;br /&gt;
	if len(line) &amp;gt; 1:&lt;br /&gt;
		#create a dict for this TA&lt;br /&gt;
		TA_dict[line[0]] = {}&lt;br /&gt;
		TA_dict[line[0]][&amp;#039;max&amp;#039;] = int(line[1])&lt;br /&gt;
		TA_dict[line[0]][&amp;#039;Students&amp;#039;] = []&lt;br /&gt;
		TA_index.append(line[0])&lt;br /&gt;
	else:&lt;br /&gt;
		TA_dict[line[0]] = {}&lt;br /&gt;
		TA_dict[line[0]][&amp;#039;max&amp;#039;] = 10&lt;br /&gt;
		TA_dict[line[0]][&amp;#039;Students&amp;#039;] = []&lt;br /&gt;
		TA_index.append(line[0])&lt;br /&gt;
&lt;br /&gt;
TA_IN.close()&lt;br /&gt;
&lt;br /&gt;
#read and save list of students&lt;br /&gt;
st_IN = open(student_file, &amp;#039;rt&amp;#039;, encoding=&amp;#039;utf8&amp;#039;)&lt;br /&gt;
st_list = []&lt;br /&gt;
for line in st_IN:&lt;br /&gt;
        if line[0] != &amp;#039;#&amp;#039;:&lt;br /&gt;
	        st_list.append(line.rstrip())&lt;br /&gt;
st_IN.close()&lt;br /&gt;
&lt;br /&gt;
#mix things up a bit&lt;br /&gt;
random.shuffle(st_list)&lt;br /&gt;
&lt;br /&gt;
random.shuffle(TA_index)&lt;br /&gt;
&lt;br /&gt;
j = 0&lt;br /&gt;
#go through the randomized student list and assign each to a TA&lt;br /&gt;
for name in st_list:&lt;br /&gt;
	#check if we&amp;#039;ve reached the end of the TA list&lt;br /&gt;
	if j == len(TA_index):&lt;br /&gt;
		j = 0&lt;br /&gt;
	#check if TA j has already hit the maximum of students. If yes, check the next and so on.&lt;br /&gt;
	while len(TA_dict[TA_index[j]][&amp;#039;Students&amp;#039;]) == TA_dict[TA_index[j]][&amp;#039;max&amp;#039;]:&lt;br /&gt;
		j += 1&lt;br /&gt;
		#if we&amp;#039;ve run through the whole list without exiting the loop there are more students than expected.&lt;br /&gt;
		if j &amp;gt;= len(TA_index):&lt;br /&gt;
			sys.exit(&amp;#039;Error: Every TA has reached their specified student limit!&amp;#039;)&lt;br /&gt;
	#now append	&lt;br /&gt;
	TA_dict[TA_index[j]][&amp;#039;Students&amp;#039;].append(name)&lt;br /&gt;
	#finally increment j&lt;br /&gt;
	j += 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
for TA in TA_index:&lt;br /&gt;
	print(TA, &amp;#039;: &amp;#039;, sep=&amp;#039;&amp;#039;, end=&amp;#039;&amp;#039;)&lt;br /&gt;
	print(&amp;#039;; &amp;#039;.join(TA_dict[TA][&amp;#039;Students&amp;#039;]))&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>WikiSysop</name></author>
	</entry>
</feed>