From 24b0db21d427dc364d7888e6126cd4bfa28dbf57 Mon Sep 17 00:00:00 2001 From: Martin Mares <mj@ucw.cz> Date: Fri, 15 Nov 2019 15:30:54 +0100 Subject: [PATCH] =?UTF-8?q?06:=20=C5=98e=C5=A1en=C3=AD=20p=C5=99=C3=ADklad?= =?UTF-8?q?=C5=AF=20z=20cvi=C4=8Den=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 07-compr/priklady.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 07-compr/priklady.py diff --git a/07-compr/priklady.py b/07-compr/priklady.py new file mode 100644 index 0000000..db3470b --- /dev/null +++ b/07-compr/priklady.py @@ -0,0 +1,23 @@ +def skalarni_soucin(x, y): + return sum([i*j for i, j in zip(x, y)]) + +def nasobilka(n): + return [[i*j for i in range(1, n+1)] for j in range(1, n+1)] + +def prunik_seznamu(x, y): + return [a for a in x if a in y] + +def palindromy(radek): + return [slovo for slovo in radek.split() if slovo == slovo[::-1]] + +def transpozice(x): + return [[a[i] for a in x] for i in range(len(x[0]))] + +def nasobeni_matic(x, y): + yt = transpozice(y) + return [[skalarni_soucin(rx, ryt) for ryt in yt] for rx in x] + +def slova_podle_delky(radek): + dvojice = [ (len(slovo), slovo) for slovo in radek.split() ] + for _, slovo in sorted(dvojice): + print(slovo) -- GitLab