Cheat Sheet sc3 <-> Python ---------------------------------------------------------------------------------------------- Geometric series Array.geom(<sz>, <strt>, <stp>) <-> range(<start>, <end>, <step>) List Comprehension collect <-> map Array.fill(<n>, <function>) <-> map(<function>, range(0, <n-1>)) <-> [<exp> for x in <array>] <-> (see [1] for further details) creating a function {|<args>| <body>} <-> def ... <-> lambda [<params>, ...]: <expr> flat an array <array>.flat <-> from numarray import array <-> a = array([1,2],[3,4]) <-> a.getflat() <-> # or <-> def flatten(a, b): <-> if isinstance(a, list): <-> [flatten(x, b) for x in a] <-> else: <-> b.append(a) <-> (example at [2] below) class creation <ClassName> : <Ancestor> { <-> class <name>(<Ancestor>): <body> <-> <body> } <-> class methods <name> {|<args>| <-> def <name>(self, <args>): <body> <-> <body> } <-> private methods pr_<name> {}// only convention <-> def __<name>(self): <body> import modules see Quarks Helpfile <-> import <modulename> <-> from <modulename> import * <-> import <modulename>.<class> <-> from <modulename> import <class> <-> import <modulename>.<class> as <name> GETTING HELP IN OSX APP <-> INTERACTIVE SHELL ----------------------------------------------------------------------------------------------- view sourcecode <cmd-y> <-> import <module> <-> dir(<module>) <-> # instance <-> import <module> <-> s = <module>.<class>() <-> dir(s) view help <cmd-?> <-> help(<helptext>)
[1] tutorial on List Comprehensions
[2] example for flatten definition
a = [[1,2],[3,4],[1,2,3]] b = [] flatten(a, b) print b #prints [1, 2, 3, 4, 1, 2, 3]
contributions by
- LFSaw.de
- Jamie Bullock
- altern