![]() |
||
| Python |
Material
Installation
Dokumentation
PythonKara
Grundlagen
Namensräume
Funktionen
Testen
Strings
Listen
Zeitmessungen
Zufall
Bits+Bytes
Module
Sockets
xml
serielle Schnittstelle
Python in HTML
Turtle
xturtle
Tkinter
OOP
Threads
Zusicherungen
exe
Patterns
GnuPlot
Goto
MySQL
CGI
Dateien
Exceptions
Grafik
Mathematik
Fischertechnik
Unicode
funktional
Iterator
Sound
C
Debugger
regex
Pfade
Docstrings
Django
Bluetooth
format
Bytecode
signal
|
|
|
Dictionary |
Rekursive Berechnungen mit hohem Aufwand - www.inf-schule.de
Memoization - das Prinzip
def f(x):
return x*x
fmemo = {}
def fm(x):
if not x in fmemo:
fmemo[x] = x*x
return fmemo[x]
Tests
>>> f(5)
25
>>> fm(5)
25
>>> fm(3)
9
>>> fm(7)
49
>>> fmemo
{3: 9, 5: 25, 7: 49}
>>> fm(3.1)
9.610000000000001
>>> fm(-0.0071)
5.041000000000001e-05
>>> fmemo
{3.1: 9.610000000000001, 3: 9, -0.0071: 5.041000000000001e-05, 5: 25, 7: 49}
Vergleiche Lösungen mit und ohne Memoizing durch Zeitmessungen.