Giter Site home page Giter Site logo

wolfram2python's Introduction

Wolfram โ†” Python

general


Name Wolfram Python
func
f[x_]:=2 + x;f[2]
def f(x):
return 2 + x
f(2)
global
Names["Global`*"]
globals()
print
Print["Hello world"]
print("Hello world")
range
Range[0,7,2]
range(0,7,2)

math


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)

dict


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())

functional programming


Name Wolfram Python
func nest
NestList[f[#]&,2,3]
def nest(f, x, times):
y = [x]
for i in range(times-1):
y.append(f(y[-1]))
return y
nest(f,2,3)
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])))

list


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])

procedural programming


Name Wolfram Python
if
If[3>2,Print["true"]]
if 3 > 2:
print("true")
for
For[i=0,i<3,i++,Print[i]]
for i in range(3):
print(i)
while
i = 0; While[i<3,Print[i];i++]
i = 0
while i < 3:
print(i)
i += 1

string


Name Wolfram Python
string format
ToString[StringForm["The values are x= and y=.", 5, 10]]
"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")

wolfram2python's People

Contributors

landajuela avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.