Python

How to Convert a Unicode String to a Dictionary in Python?

Problem Formulation Given a Unicode string representation of a dictionary. How to convert it to a dictionary? Input: u”{‘a’: 1, ‘b’: 2, ‘c’: 3}” Output: {‘a’: 1, ‘b’: 2, ‘c’: 3} Note: The u’string’ representation represents a Unicode string that was introduced in Python 3. This is redundant as all strings in Python 3 are …

How to Convert a Unicode String to a Dictionary in Python? Read More »

Python List of Dunder Methods

When searching for a list of dunder methods, I only found a couple of resources all over the web—each covering only a fraction of dunder methods. So, here’s my collection of 127 dunder methods (also called “magic methods”) from those sources, sorted alphabetically: __abs__ __add__ __aenter__ __aexit__ __aiter__ __and__ __anext__ __await__ __bool__ __bytes__ __call__ __ceil__ …

Python List of Dunder Methods Read More »

Python Version Backward Compatibility

The Python language does not generally provide backward compatibility. The ability to break inefficiencies and fix wrong design choices are major reasons why Python has remained lean and efficient over the last decades. However, the PEP 387 standard discusses that incompatibility issues should be well thought out. Here’s the basic policy when backward incompatibilities may …

Python Version Backward Compatibility Read More »

bootstrap_plot() – Pandas Plotting Module

A bootstrap plot is a graphical representation of uncertainty in a characteristic chosen from within a population. While we can usually calculate data confidence levels mathematically, gaining access to the desired characteristics from some populations is impossible or impracticable. In this case, bootstrap sampling and the bootstrap plot come to our aid. This article will …

bootstrap_plot() – Pandas Plotting Module Read More »

How to Check the Python Version at Runtime?

Method 1: sys.version To check your version at runtime in your code, import the sys module and print the sys.version attribute to your Python shell: Method 2: sys.version_info If you need an easy-to-process output for the major, minor, and micro versions, use the sys.version_info attribute. For example, Python version 3.9.5 has major version 3, minor …

How to Check the Python Version at Runtime? Read More »