Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Čermák Petr
Prm1
Commits
96a91b63
Commit
96a91b63
authored
Nov 01, 2019
by
Mareš Martin
Browse files
06: Seznamy, řezy, řetězce
parent
a2ecd9ff
Changes
3
Hide whitespace changes
Inline
Side-by-side
06-rezy/06-rezy.tex
0 → 100644
View file @
96a91b63
\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}
06-rezy/Makefile
0 → 100644
View file @
96a91b63
SLIDES
=
06-rezy.pdf
include
../Makerules
slidemac.tex
View file @
96a91b63
...
...
@@ -13,3 +13,5 @@
\fi
\medskip
}
\def\cmt
#1
{
\quad\hbox
{
\color
{
black
}
\rm
#1
}}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment