Julia

% julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.5.1 (2020-08-25)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

Python

% python
Python 3.8.5 (default, Aug  5 2020, 08:22:02) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

Get the list of all files

Julia: Base.Filesystem.readdir

julia> readdir()
20-element Array{String,1}:
 ".dockerenv"
 "bin"
 "boot"
 "dev"
 "etc"
 "home"
 "lib"
 "lib64"
 "media"
 
 "root"
 "run"
 "sbin"
 "srv"
 "sys"
 "tmp"
 "usr"
 "var"

Python: os.listdir

>>> import os
>>> os.listdir()
['lib', 'home', 'etc', 'media', 'var', 'srv', 'sys', 'bin', 'usr', 'root', 'boot', 'tmp', 'dev', 'opt', 'mnt', 'lib64', 'proc', 'run', 'sbin', '.dockerenv']

Join path components

Julia: Base.Filesystem.joinpath

julia> joinpath("/home", "file.txt")
"/home/file.txt"

Python: os.path.join

>>> import os
>>> os.path.join('/home', 'file.txt')
'/home/file.txt'

Get the current working directory

Julia: Base.@__DIR__

julia> @__DIR__
"/"

Python: os.getcwd

>>> import os
>>> os.getcwd()
'/'

Get the running file path

Julia: Base.@__FILE__

Python: __path__


Return an array of zeros with the same shape

Julia: Base.zero

julia> x = 1:6
1:6

julia> x = reshape(x, 2, 3)
2×3 reshape(::UnitRange{Int64}, 2, 3) with eltype Int64:
 1  3  5
 2  4  6

julia> zero(x)
2×3 Array{Int64,2}:
 0  0  0
 0  0  0

Python: numpy.zeros_like

>>> import numpy as np
>>> x = np.arange(6)
>>> x = x.reshape((2, 3))
>>> x
array([[0, 1, 2],
       [3, 4, 5]])
>>> np.zeros_like(x)
array([[0, 0, 0],
       [0, 0, 0]])

Return an array of ones with the same shape

Julia: Base.fill! + Base.similar

julia> x = 1:6
1:6

julia> x = reshape(x, 2, 3)
2×3 reshape(::UnitRange{Int64}, 2, 3) with eltype Int64:
 1  3  5
 2  4  6

julia> x = collect(x)
2×3 Array{Int64,2}:
 1  3  5
 2  4  6

julia> fill!(similar(x), 1)
2×3 Array{Int64,2}:
 1  1  1
 1  1  1

Python: numpy.ones_like

>>> import numpy as np
>>> x = np.arange(6)
>>> x = x.reshape((2, 3))
>>> x
array([[0, 1, 2],
       [3, 4, 5]])
>>> np.ones_like(x)
array([[1, 1, 1],
       [1, 1, 1]])

Get the value for the given key if key is in dictionary, and return the default value if the key is not found

Julia: Base.get

julia> d = Dict("a"=>1, "b"=>2)
Dict{String,Int64} with 2 entries:
  "b" => 2
  "a" => 1

julia> get(d, "a", 0)
1

julia> get(d, "c", 0)
0

Python: dict.get

>>> d = {'a': 1, 'b': 2}
>>> d.get('a', 0)
1
>>> d.get('c', 0)
0