From 96a91b63c63eb721e51e8ce16465fd38d3476626 Mon Sep 17 00:00:00 2001 From: Martin Mares <mj@ucw.cz> Date: Fri, 1 Nov 2019 23:01:56 +0100 Subject: [PATCH] =?UTF-8?q?06:=20Seznamy,=20=C5=99ezy,=20=C5=99et=C4=9Bzce?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 06-rezy/06-rezy.tex | 231 ++++++++++++++++++++++++++++++++++++++++++++ 06-rezy/Makefile | 3 + slidemac.tex | 2 + 3 files changed, 236 insertions(+) create mode 100644 06-rezy/06-rezy.tex create mode 100644 06-rezy/Makefile diff --git a/06-rezy/06-rezy.tex b/06-rezy/06-rezy.tex new file mode 100644 index 0000000..90edc99 --- /dev/null +++ b/06-rezy/06-rezy.tex @@ -0,0 +1,231 @@ +\documentclass{beamer} +\usepackage[utf8]{inputenc} +\usepackage[czech]{babel} +\usepackage{palatino} +\usepackage{verbatim} +\usetheme{Warsaw} +\title{Programování 1: Seznamy a řezy} +\author[Martin Mareš]{Martin Mareš\\\texttt{mj@ucw.cz}} +\institute{Katedra Aplikované Matematiky\\MFF UK Praha} +\date{2019} +\begin{document} +\setbeamertemplate{navigation symbols}{} +\setbeamertemplate{footline}{} +\setbeamerfont{title page}{family=\rmfamily} +\shorthandoff{"} + +\begin{frame} +\titlepage +\end{frame} + +\input ../slidemac.tex + +% ---------------------------------------------------------------------- + +\begin{frame}{Řez seznamem} + +\py{% +x = [11, 22, 33, 44, 55, 66, 77] \\ +x[2:5] +}{% +[33, 44, 55] \cmt{(podseznam)} +} + +\py{% +x[:3] +}{% +[11, 22, 33] \cmt{(prefix)} +} + +\py{% +x[5:] +}{% +[66, 77] \cmt{(suffix)} +} + +\py{% +x[:] +}{% +[11, 22, 33, 44, 55, 66, 77] \cmt{(kopie seznamu)} +} + +\py{% +x[::2] +}{% +[11, 33, 55, 77] \cmt{(každý druhý prvek)} +} + +\py{% +x[::-1] +}{% +[77, 66, 55, 44, 33, 22, 11] \cmt{(pozpátku)} +} + +\end{frame} + +% ---------------------------------------------------------------------- + +\begin{frame}{Operace se seznamy} + +\py{% +x = [1, 2, 3, 4, 5] \\ +x.pop() \cmt{(odebere z konce)} +}{% +5 +} + +\py{% +x.pop(0) \cmt{(odebere na zadané pozici)} +}{% +1 +} + +\py{% +x \cmt{(co zbylo)} +}{% +[2, 3, 4] +} + +\py{% +x.insert(1, 42) \cmt{(vloží na zadanou pozici)} \\ +x +}{% +[2, 42, 3, 4] +} + +\py{% +help(x) \cmt{(vypíše dostupné operace)} +}{% +} + +\py{% +help([]) \cmt{(totéž)} +}{% +} + +\end{frame} + +% ---------------------------------------------------------------------- + +\begin{frame}{Použití řezů} + +\py{% +x = [11, 22, 33, 44, 55, 66, 77] \\ +x[:3] + x[4:] +}{% +[11, 22, 33, 55, 66, 77] \cmt{(vypuštění prvku)} +} + +\py{% +x[:3] + [0] + x[3:] \cmt{(vložení prvku)} +}{% +[11, 22, 33, 0, 44, 55, 66, 77] +} + +\py{% +x[2:4] = [1, 2, 3, 4] \\ +x +}{% +[11, 22, 1, 2, 3, 4, 55, 66, 77] \cmt{(přiřazení do řezu)} +} + +\py{% +y=[1,2,3] \\ +y[0:0] = [1] \\ +y +}{% +[0, 1, 2, 3] \cmt{(jiný způsob, jak vložit prvek)} +} + +\end{frame} + +% ---------------------------------------------------------------------- + +\begin{frame}{Řetězce se chovají jako seznamy} + +\py{% +x="Sedmikráska" \\ +len(x) +}{% +11 +} + +\py{% +x[0] +}{% +'S' +} + +\py{% +x[:4] + x[10] +}{% +'Sedma' +} + +\py{% +x[0]="s" +}{% +<chyba> \cmt{(řetězce nelze měnit)} +} + +\py{% +for a in x: \. +\>print(a) +}{% +S \\ +e \\ +... +} + +\end{frame} + +% ---------------------------------------------------------------------- + +\begin{frame}{Operace s řetězci} + +\py{% +"velká".upper() +}{% +'VELKÁ' +} + +\py{% +"banana".find("na") +}{% +2 +} + +\py{% +"banana".find("baba") +}{% +-1 +} + +\py{% +"Na počátku bylo~~~slovo.".split() +}{% +['Na', 'počátku', 'bylo', 'slovo.'] +} + +\py{% +"+".join(["Alice", "Bob", "Cyril"]) +}{% +'Alice+Bob+Cyril' +} + +\py{% +"1+2+3".split(sep="+") +}{% +['1', '2', '3'] +} + +\py{% +help("") +}{% +} + +\end{frame} + +% ---------------------------------------------------------------------- + +\end{document} diff --git a/06-rezy/Makefile b/06-rezy/Makefile new file mode 100644 index 0000000..8cb9b74 --- /dev/null +++ b/06-rezy/Makefile @@ -0,0 +1,3 @@ +SLIDES=06-rezy.pdf + +include ../Makerules diff --git a/slidemac.tex b/slidemac.tex index 0a5c4be..c00e75f 100644 --- a/slidemac.tex +++ b/slidemac.tex @@ -13,3 +13,5 @@ \fi \medskip } + +\def\cmt#1{\quad\hbox{\color{black}\rm #1}} -- GitLab