This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | fuss:python [2020/02/25 02:07] – [Only in (Monty) Python] office | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Serve Current Directory over HTTP ====== | ||
+ | The following command: | ||
+ | <code python> | ||
+ | python -m SimpleHTTPServer 8181 | ||
+ | </ | ||
+ | will serve the current directory where the command is executed by starting a HTTP server on port '' | ||
+ | |||
+ | ====== Reverse List ====== | ||
+ | |||
+ | The '' | ||
+ | |||
+ | <code python> | ||
+ | ########################################################################### | ||
+ | ## Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 ## | ||
+ | ########################################################################### | ||
+ | def wasListReverse (l): | ||
+ | if len(l) <= 1: | ||
+ | return l | ||
+ | return listReverse(l[1: | ||
+ | </ | ||
+ | |||
+ | Example call: | ||
+ | <code python> | ||
+ | i = [" | ||
+ | print listReverse(i) | ||
+ | </ | ||
+ | |||
+ | Output: | ||
+ | < | ||
+ | [39, 22, 11, ' | ||
+ | </ | ||
+ | |||
+ | ===== Derivations ===== | ||
+ | |||
+ | Using the programming language' | ||
+ | |||
+ | ==== Using the Ternary Operator ==== | ||
+ | |||
+ | The '' | ||
+ | |||
+ | <code python> | ||
+ | ########################################################################### | ||
+ | ## Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 ## | ||
+ | ########################################################################### | ||
+ | def listReverseTern (l): | ||
+ | return l if len(l) <= 1 else listReverseTern(l[1: | ||
+ | </ | ||
+ | |||
+ | |||
+ | ==== Using Lambda Expressions ==== | ||
+ | |||
+ | The '' | ||
+ | <code python> | ||
+ | ########################################################################### | ||
+ | ## Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 ## | ||
+ | ########################################################################### | ||
+ | |||
+ | wasListReverseLambda = lambda x : x if len(x) <= 1 else wasListReverseLambda(x[1: | ||
+ | </ | ||
+ | |||
+ | Example call: | ||
+ | <code python> | ||
+ | wasListReverseLambda = lambda x : x if len(x) <= 1 else wasListReverseLambda(x[1: | ||
+ | |||
+ | print wasListReverseLambda([" | ||
+ | </ | ||
+ | |||
+ | Output: | ||
+ | < | ||
+ | [39, 22, 11, ' | ||
+ | </ | ||
+ | |||
+ | ====== Y-Combinator ====== | ||
+ | |||
+ | By expressing the $Y$ combinator using the $\omega$ combinator [[fuss/ | ||
+ | |||
+ | <code python> | ||
+ | # | ||
+ | ########################################################################### | ||
+ | ## Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 ## | ||
+ | ########################################################################### | ||
+ | |||
+ | w = lambda x : x( x ); | ||
+ | Y = lambda y : w( lambda f : y( lambda x : w(f)(x) ) ); | ||
+ | </ | ||
+ | |||
+ | An example call, to calculate the factorial of $10$, would be: | ||
+ | |||
+ | <code python> | ||
+ | Factorial = Y( lambda f : lambda n : 1 if n <= 1 else n * f(n - 1) ); | ||
+ | print Factorial(10); | ||
+ | </ | ||
+ | |||
+ | ====== Only in (Monty) Python ====== | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ====== Memory Error When Installing Packages with Pip ====== | ||
+ | |||
+ | In case packages cannot be installed and a '' |