Comparison table of frequently used processes of Python and Clojure

This is a personal note.

String processing

Split the string with spaces

(require '[clojure.string :as str])
(str/split "spam egg ham" #" ")
; ["spam" "egg" "ham"]
>>> "spam egg ham".split()
['spam', 'egg', 'ham']

Get Unicode code point

(int (.charAt "Liquor" 0)
; 37202
(format "%x" (int (.charAt "Liquor" 0)))
; "9152"
>>> ord(u"Liquor")
37202
>>> hex(ord(u"Liquor"))
'0x9152'

File processing

Get a temporary directory

Clojure

user=> (System/getProperty "java.io.tmpdir")
"/tmp"

For Clojure, using fs seems to be more like Clojure.

user=> (require '[me.raynes.fs :as fs])
nil
user=> (fs/tmpdir)
"/tmp"

Python

>>> import tempfile
>>> tempfile.gettempdir()
'/tmp'

Time processing

Don't just do your best with the standard library, Python dateutil, Clojure clj-time Isn't it better to use -time)?

Get Unix time stamps from ISO format strings

(require '[clj-time.coerce :as c])
(require '[clj-time.local :as l])
(/ (c/to-long (l/to-local-date-time "2015-11-24T22:00:00+09:00")) 1000)
; 1448370000
>>> import dateutil.parser
>>> import time
>>> time.mktime(dateutil.parser.parse("2015-11-24T22:00:00+09:00").utctimetuple())
1448370000.0

Generate a time object from a Unix time stamp

(require '[clj-time.coerce :as c])
(c/from-long (* 1448370000 1000))
; #object[org.joda.time.DateTime 0x6f5185fe "2015-11-24T13:00:00.000Z"]
>>> import datetime
>>> datetime.datetime.utcfromtimestamp(1448370000.0)
datetime.datetime(2015, 11, 24, 13, 0)

Recommended Posts

Comparison table of frequently used processes of Python and Clojure
Summary of differences between Python and PHP (comparison table of main items)
Paiza Skill Check List of Frequently Used D and C Ranks ~ Python ~
List of frequently used built-in functions and methods
Frequently used methods of Selenium and Beautiful Soup
Summary of frequently used Python arrays (for myself)
Comparison of R and Python writing (Euclidean algorithm)
Comparison of Python and Ruby (Environment / Grammar / Literal)
Comparison of CoffeeScript with JavaScript, Python and Ruby grammar
[Python] Frequently used library code
Comparison of 4 Python web frameworks
Frequently used subpackages of SciPy
Python frequently used code snippets
Python 3 sorted and comparison functions
Comparison of Apex and Lamvery
Source installation and installation of Python
Environment construction of python and opencv
[Python] A memo of frequently used phrases (by myself) in Python scripts
The story of Python and the story of NaN
Speed comparison of Wiktionary full text processing with F # and Python
Java and Python basic grammar comparison
Installation of SciPy and matplotlib (Python)
8 Frequently Used Commands in Python Django
Anaconda and Python version correspondence table
[Python] [Table of Contents Links] Python Programming
This and that of python properties
Python Math Series ⓪ Table of Contents
List of frequently used Linux commands
Speed comparison of Python XML parsing
[Anaconda3] Summary of frequently used commands
Introductory table of contents for python3
Coexistence of Python2 and 3 with CircleCI (1.0)
Summary of Python indexes and slices
[Python] Basic pattern and usage of if statement (comparison operator and Boolean operator)
Reputation of Python books and reference books
Modules of frequently used functions in Python (such as reading external files)
[Linux] Review of frequently used basic commands 2
Summary of frequently used commands in matplotlib
Python + Selenium Frequently used operation method summary
(Java, JavaScript, Python) Comparison of string processing
Extraction of tweet.js (json.loads and eval) (Python)
[python] Frequently used techniques in machine learning
Connect a lot of Python or and and
Comparison of class inheritance and constructor description
I installed and used Numba with Python3.5
[Linux] Review of frequently used basic commands
[Machine learning] List of frequently used packages
Comparison of Python serverless frameworks-Zappa vs Chalice
Comparison of L1 regularization and Leaky Relu
Easy introduction of python3 series and OpenCV3
[Python] Various combinations of strings and values
Idempotent automation of Python and PyPI setup
Full understanding of Python threading and multiprocessing
Comparison of matrix transpose speeds with Python
Project Euler # 1 "Multiples of 3 and 5" in Python
Speed comparison of murmurhash3, md5 and sha1
[Python] Comparison of Principal Component Analysis Theory and Implementation by Python (PCA, Kernel PCA, 2DPCA)
List of main probability distributions used in machine learning and statistics and code in python
Allows you to enter frequently used parentheses and equals in python without Shift
Correspondence summary of array operation of ruby and python
[Python/Django] Summary of frequently used commands (3) <Operation of PostgreSQL>