How can I represent an ‘Enum’ in Python?

Enums have been added to Python 3.4 as described in PEP 435. It has also been backported to 3.3, 3.2, 3.1, 2.7, 2.6, 2.5, and 2.4 on pypi. For more advanced Enum techniques try the aenum library (2.7, 3.3+, same author as enum34. Code is not perfectly compatible between py2 and py3, e.g. you’ll need … Read more

What is the use of “assert” in Python?

The assert statement exists in almost every programming language. It helps detect problems early in your program, where the cause is clear, rather than later when some other operation fails. When you do… … you’re telling the program to test that condition, and immediately trigger an error if the condition is false. In Python, it’s … Read more

How to format a JavaScript date

For custom-delimited date formats, you have to pull out the date (or time) components from a DateTimeFormat object (which is part of the ECMAScript Internationalization API), and then manually create a string with the delimiters you want. To do this, you can use DateTimeFormat#formatToParts. You could destructure the array, but that is not ideal, as … Read more

What is lexicographical order?

lexicographical order is alphabetical order. The other type is numerical ordering. Consider the following values, Those values are in lexicographical order. 10 comes after 2 in numerical order, but 10 comes before 2 in “alphabetical” order.