Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Programování 1 pro matematiky
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Mareš
Programování 1 pro matematiky
Commits
1181c3a8
Commit
1181c3a8
authored
4 years ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Lambda: Příklady
parent
0487041b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
10-lambda/jmena.py
+15
-0
15 additions, 0 deletions
10-lambda/jmena.py
10-lambda/redukce.py
+28
-0
28 additions, 0 deletions
10-lambda/redukce.py
with
43 additions
and
0 deletions
10-lambda/jmena.py
0 → 100644
+
15
−
0
View file @
1181c3a8
# Seřadí primárně podle příjmení, sekundárně podle jména
def
serad
(
jmena
):
def
klic
(
jp
):
jmeno
,
prijmeni
=
jp
.
split
()
return
prijmeni
,
jmeno
return
sorted
(
jmena
,
key
=
klic
)
# Jiné řešení
def
serad2
(
jmena
):
return
sorted
(
jmena
,
key
=
lambda
jp
:
jp
.
split
()[::
-
1
])
jmena
=
[
"
Vodník Česílko
"
,
"
Jelen Větrník
"
,
"
Loupežník Rumcajz
"
,
"
Kapr Kulda
"
]
print
(
serad
(
jmena
))
This diff is collapsed.
Click to expand it.
10-lambda/redukce.py
0 → 100644
+
28
−
0
View file @
1181c3a8
def
red
(
s
,
f
):
x
=
s
[
0
]
for
i
in
range
(
1
,
len
(
s
)):
x
=
f
(
x
,
s
[
i
])
return
x
def
prvni_nenulovy
(
s
):
def
f
(
x
,
y
):
if
x
!=
0
:
return
x
else
:
return
y
return
red
(
s
,
f
)
# Zde předpokládáme, že seznam neobsahuje None
# (dalo by se to obejít tak, že bychom místo None použili jakýkoliv
# nově vytvořený objekt, třeba prázdný seznam)
def
vsechny_stejne
(
s
):
def
g
(
x
,
y
):
if
x
is
None
or
x
!=
y
:
return
None
else
:
return
x
return
red
(
s
,
g
)
is
not
None
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment