Skip to content

Commit 7962dad

Browse files
committed
several improvements, plus Liu Hui image with permission
1 parent a34f554 commit 7962dad

File tree

11 files changed

+196
-85
lines changed

11 files changed

+196
-85
lines changed

LICENSE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The list of files not under the CC BY‑NC‑SA 4.0 license bu
1212
- text/main/introduction/pythonLogo.pdf
1313
- text/main/introduction/pythonLogo.svg
1414
+ all screenshots from websites
15+
+ The illustration of LIU Hui (刘徽) in file "text/main/basics/variables/assignment/liu_hui.jpg" is from Wenqi Ying (应雯棋), editor. Commemoration of Ancient Chinese Mathematical Master Liu Hui for his Timeless Influence on Mathematics and Civilizational Exchange. [Issue 48 of CAST Newsletter](https://english.cast.org.cn/cms_files/filemanager/1941250207/attach/202412/8f23655a82364d19ad7874eb37b23035.pdf). China, Beijing (中国北京市): 中国科学技术协会 (China Association for Science and Technology, CAST), 2024. Permission was granted to include it in this material, but the copyright remains with CAST.
1516

1617

1718
## creative commons

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Die Slides zum Kurs in deutscher Sprache können unter <https://thomasweise.gith
3737
12. [`None`](https://thomasweise.github.io/programmingWithPythonSlidesDE/12_none.pdf)
3838
13. [Variablen: Wertzuweisung](https://thomasweise.github.io/programmingWithPythonSlidesDE/13_variablen_wertzuweisung.pdf)
3939
14. [Fehler im Kode mit Exceptions und IDE finden](https://thomasweise.github.io/programmingWithPythonSlidesDE/14_fehler_im_kode_mit_exceptions_und_ide_finden.pdf)
40+
15. [Variablentypen und Type Hints](https://thomasweise.github.io/programmingWithPythonSlidesDE/15_variablentypen_und_type_hints.pdf)
4041

4142
### 2.3. The Slides in English
4243
The slides for the course are available at <https://thomasweise.github.io/programmingWithPythonSlides> and also listed below.
@@ -71,6 +72,7 @@ The list of files not under the CC&nbsp;BY&#8209;NC&#8209;SA&nbsp;4.0 license bu
7172
- text/main/introduction/pythonLogo.pdf
7273
- text/main/introduction/pythonLogo.svg
7374
+ all screenshots from websites
75+
+ The illustration of LIU Hui (刘徽) in file "text/main/basics/variables/assignment/liu_hui.jpg" is from Wenqi Ying (应雯棋), editor. Commemoration of Ancient Chinese Mathematical Master Liu Hui for his Timeless Influence on Mathematics and Civilizational Exchange. [Issue 48 of CAST Newsletter](https://english.cast.org.cn/cms_files/filemanager/1941250207/attach/202412/8f23655a82364d19ad7874eb37b23035.pdf). China, Beijing (中国北京市): 中国科学技术协会 (China Association for Science and Technology, CAST), 2024. Permission was granted to include it in this material, but the copyright remains with CAST.
7476

7577
You can download its newest version of the course material from <https://thomasweise.github.io/databases>.
7678
This version may change since this course and book both are work in progress.

text/main/basics/collections/dictionaries/dictionaries.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
The value associated with a given key is accessed via the \pythonil{[...]}\pythonIdx{[\idxdots]}-based indexing.
1010
The keys are unique and can be of an arbitrary type, as long as they are immutable.
1111
The concept of dictionary is also known as hash table or hash map in other languages or domains.
12-
Sets and dictionaries in \python\ are implemented using similar datastructures~\cite{B2023T}, namely hash tables~\cite{K1998SAS,CLRS2009ITA,SKS2019DSC}, and thus exhibit similar performance.%
12+
Sets and dictionaries in \python\ are implemented using similar datastructures~\cite{PSF:TPW:TC}, namely hash tables~\cite{K1998SAS,CLRS2009ITA,SKS2019DSC}, and thus exhibit similar performance.%
1313
%
1414
\begin{sloppypar}%
1515
\cref{lst:dicts:dicts_1} shows some examples of how we can use dictionaries.

text/main/basics/collections/sets/sets.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
So what is the advantage of sets?
4747
Sets are fast.
4848
In \python, sets are implemented based on the concept of hash tables and thus inherit the computational performance of these datastructures~\cite{K1998SAS,CLRS2009ITA,SKS2019DSC}.
49-
The operation for checking whether one object is contained in a set can be done in \bigOb{1} in average, whereas lists need \bigOb{n} in average, with $n$~being the list length~\cite{H2025PM:PBOTTCODDSIPP33,B2023T,N2022CCSFPO}.
49+
The operation for checking whether one object is contained in a set can be done in \bigOb{1} in average, whereas lists need \bigOb{n} in average, with $n$~being the list length~\cite{H2025PM:PBOTTCODDSIPP33,PSF:TPW:TC,N2022CCSFPO}.
5050
This means that checking whether an element is contained in a set costs approximately a constant number of CPU cycles, whereas doing the same for a list takes a number of cycles roughly linear in the length of the list.
5151
Lists thus can be preferred if we either only have very few elements to check or if we need to access elements using integer indices.
5252
If we have more than just very few elements and/or need to perform set operations such as those discussed in the following text, sets are the way to go.%

text/main/basics/variables/assignment/assignment.tex

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,14 @@
234234
%
235235
\begin{figure}%
236236
\centering%
237+
\includegraphics[width=0.3\linewidth]{\currentDir/liu_hui.jpg}%
238+
\caption{Modern rendition of LIU Hui~(刘徽) from~\cite{Y2024COACMMLHFHTIOMACE}. %
239+
Not under the Creative Commons license, copyright~\textcopyright\ is with CAST / Official WeChat account of VOC.}%
240+
\label{fig:liu_hui}%
241+
\end{figure}%
242+
%
243+
\begin{figure}%
244+
\centering%
237245
\includegraphics[width=0.99\linewidth]{\currentDir/liuHuiCircle}%
238246
\caption{Approximating the ratio of the circumference and the diameter of a circle, i.e., $\numberPi$, by inscribing regular~$3*2^n$-gons.}%
239247
\label{fig:liuHuiCircle}%
@@ -260,7 +268,7 @@
260268
But we can never really write it down in its entirety.
261269

262270
Well, when I say \inQuotes{we can compute it}, then the question \inQuotes{How?} immediately arises.
263-
One particularly ingenious answer was given by the Chinese mathematician LIU Hui~(刘徽) somewhere in the third century~\pgls{CE}~\cite{OR2003LH,Y2024COACMMLHFHTIOMACE} in his commentary to the famous Chinese mathematics book \emph{Jiu Zhang Suanshu}~(九章算术)~\cite{OR2003LH,SCL1999TNCOTMACAC,S1998LHATFGAOCM,D2010AALHOCAS,C2002LFLHADWTDM}.
271+
One particularly ingenious answer was given by the Chinese mathematician LIU Hui~(刘徽, who may have looked as sketched \cref{fig:liu_hui}) somewhere in the third century~\pgls{CE}~\cite{OR2003LH,Y2024COACMMLHFHTIOMACE} in his commentary to the famous Chinese mathematics book \emph{Jiu Zhang Suanshu}~(九章算术)~\cite{OR2003LH,SCL1999TNCOTMACAC,S1998LHATFGAOCM,D2010AALHOCAS,C2002LFLHADWTDM}.
264272
In \cref{fig:liuHuiCircle}, we show how~\numberPi\ can be approximated based on the idea of LIU Hui~(刘徽):
265273
By inscribing regular~$e$\nobreakdashes-gons with an increasing number~$e$ of edges into a circle such that the corners of the $e$\nobreakdashes-gons lie on the circle.
266274

234 KB
Loading

text/main/basics/variables/multiAndSwap/multiAndSwap.tex

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,30 @@
55
A \python\ program assigning multiple values to multiple variables and using the same method to swap variable values.}{}%
66
%
77
Let us return to the topic of variables and assignments.
8-
In \python, we can assign values to multiple variables at once.
8+
In \python, we can assign values to multiple variables at once~(ofcourse, always exactly one value to one variable).
99
In this case, we separate both the variable names and the values with commas.
10-
The first line (\pythonil{a, b = 5, 10}\pythonIdx{=!multiple}\pythonIdx{,}) in \cref{lst:variables:multi_and_swap} assigns the values~\pythonil{5} and~\pythonil{10}, respectively, to the variables~\pythonil{a} and~\pythonil{b}, respectively.
10+
The first line~\pythonil{a, b = 5, 10}\pythonIdx{=!multiple}\pythonIdx{,} in \cref{lst:variables:multi_and_swap} is equivalent to the two lines~\pythonil{a = 5} and~\pythonil{b = 10}.
11+
It assigns the value~\pythonil{5} to the variable~\pythonil{a} and the value~\pythonil{10} to the variable~\pythonil{b}.
1112
After this assignment step, \pythonil{a == 5} and \pythonil{b == 10} holds.
12-
\pythonil{print(f"a={a}, b={b}")} therefore prints \textit{a=5, b=10}.
13+
\pythonil{print(f\" \{a = \}, \{b = \}\")} therefore prints \textit{a = 5, b = 10}.
1314

1415
This method can also be used to \emph{swap} the values of two variables\pythonIdx{=!swap}\pythonIdx{swap}.
15-
Writing \pythonil{a, b = b, a} looks a bit strange but it basically means \inQuotes{the \emph{new} value of \pythonil{a} will be the \emph{present} value of \pythonil{b} and the \emph{new} value of \pythonil{b} will be the \emph{present} value of \pythonil{a}.}
16-
The line is therefore basically equivalent to first storing~\pythonil{a} in a temporary variable~\pythonil{t}, then overwriting \pythonil{a} with \pythonil{b}, and finally copying the value of \pythonil{t} to \pythonil{t}.
17-
But it accomplishes this in single line of code instead of three.
18-
\pythonil{print(f"a={a}, b={b}")} thus now prints \textit{a=10, b=5}.%
16+
Writing \pythonil{a, b = b, a} looks a bit strange but it basically means \inQuotes{the \emph{new} value of~\pythonil{a} will be the \emph{present} value of~\pythonil{b} and the \emph{new} value of~\pythonil{b} will be the \emph{present} value of~\pythonil{a}.}
17+
The line is therefore basically equivalent zu \pythonil{t = a}, \pythonil{a = b}, and \pythonil{b = t}.
18+
Without the double-assignment, we would first have to store the value of~\pythonil{a} in some temporary variable~\pythonil{t}, then overwrite \pythonil{a} with \pythonil{b}, and finally we would copy the value of \pythonil{t} to \pythonil{b}.
19+
But with the double-assignment, we can accomplishes this in single line of code instead of three.
20+
And we do not need a temporary variable either.
21+
\pythonil{print(f\" \{a = \}, \{b = \}\")} thus now prints \textit{a=10, b=5}.%
1922
%
2023
\bestPractice{swap}{Swapping of variable values can best be done with a multi-assignment statement, e.g., \pythonil{a, b = b, a}\pythonIdx{=!swap}\pythonIdx{swap}.}%
2124
%
2225
The same concept of multiple assignments works for arbitrarily many variables.
2326
\pythonil{z, y, x = 1, 2, 3} assigns, respectively, \pythonil{1} to \pythonil{z}, \pythonil{2} to \pythonil{y}, and \pythonil{3} to \pythonil{x}.
24-
\pythonil{print(f"x={x}, y={y}, z={z}")} thus yields \textil{x=3, y=2, z=1}.
27+
\pythonil{print(f\"\{x = \}, \{y = \}, \{z = \}\")} thus yields \textil{x = 3, y = 2, z = 1}.
2528

2629
We can also swap multiple values.
2730
\pythonil{x, y, z = z, y, x} assigns the present value of \pythonil{z} to become the new value of \pythonil{x}, the present value of \pythonil{y} to also be the new value of \pythonil{y}, and the present value of \pythonil{x} to become the new value of \pythonil{z}.
28-
\pythonil{print(f"x={x}, y={y}, z={z}")} now gives us \textil{x=1, y=2, z=3}.
31+
\pythonil{print(f\"\{x = \}, \{y = \}, \{z = \}\")} now gives us \textil{x = 1, y = 2, z = 3}.
2932
%
3033
\FloatBarrier%
3134
\endhsection%

0 commit comments

Comments
 (0)