Name | Wolfram | Python |
---|---|---|
func | f[x_]:=2 + x;f[2] |
def f(x): |
global | Names["Global`*"] |
globals() |
Print["Hello world"] |
print("Hello world") |
|
range | Range[0,7,2] |
range(0,7,2) |
Name | Wolfram | Python |
---|---|---|
abs | Abs[-2] |
abs(-2) |
ceil | Ceiling[2.3] |
ceil(2.3) |
floor | Floor[2.3] |
floor(2.3) |
max | Max[2,3] |
max(2,3) |
min | Min[2,3] |
min(2,3) |
pow | 2^3 |
2**3 |
round | Round[2.3] |
round(2.3) |
sqrt | Sqrt[2] |
sqrt(2) |
Name | Wolfram | Python |
---|---|---|
dict | <|"a" -> 2, "b" -> 2, "c" -> 6, "d" -> 7|> |
{"a": 2, "b": 2, "c": 6, "d": 7} |
dict access | <|"a" -> 2, "b" -> 2, "c" -> 6, "d" -> 7|>["a"] |
{"a": 2, "b": 2, "c": 6, "d": 7}["a"] |
dict keys | Keys[<|"a" -> 2, "b" -> 2, "c" -> 6, "d" -> 7|>] |
list({"a": 2, "b": 2, "c": 6, "d": 7}.keys()) |
dict values | Values[<|"a" -> 2, "b" -> 2, "c" -> 6, "d" -> 7|>] |
list({"a": 2, "b": 2, "c": 6, "d": 7}.values()) |
Name | Wolfram | Python |
---|---|---|
func nest | NestList[f[#]&,2,3] |
def nest(f, x, times): |
map | Function[x,2 + x]/@{2, 2, 6, 7} |
map(lambda x : 2 + x, [2, 2, 6, 7]) |
filter | Function[x,2 + x]/@Select[{2, 2, 6, 7},#>4&] |
list(map(lambda x : 2 + x, filter(lambda x : x > 4, [2, 2, 6, 7]))) |
Name | Wolfram | Python |
---|---|---|
list | {2, 2, 6, 7} |
[2, 2, 6, 7] |
list append | l={2, 2, 6, 7}; AppendTo[l,2]; l |
l=[2, 2, 6, 7]; l.append(2); l |
list length | Length[{2, 2, 6, 7}] |
len([2, 2, 6, 7]) |
list slicing | {2, 2, 6, 7}[[1;;;;2]] |
[2, 2, 6, 7][0::2] |
list zip | Transpose@{{"a", "b", "c", "d"},{2, 2, 6, 7}} |
list(zip(["a", "b", "c", "d"],[2, 2, 6, 7])) |
unique list | DeleteDuplicates[{2, 2, 6, 7}] |
set([2, 2, 6, 7]) |
Name | Wolfram | Python |
---|---|---|
if | If[3>2,Print["true"]] |
if 3 > 2: |
for | For[i=0,i<3,i++,Print[i]] |
for i in range(3): |
while | i = 0; While[i<3,Print[i];i++] |
i = 0 |
Name | Wolfram | Python |
---|---|---|
string format | ToString[StringForm["The values are x= |
"The values are x={} and y={}.".format(5, 10) |
string join | StringRiffle[{2, 2, 6, 7}, " "] |
' '.join(["2", "2", "6", "7"]) |
string split | StringSplit["a b c d", " "] |
"a b c d".split(" ") |
string to int | ToExpression["2"] |
int("2") |
string to list | Characters["abcd"] |
list("abcd") |