Call math.log(x) on a number x to return the natural logarithm of x.
This snippet fetches the list of files in a directory sorting them by their names using os.listdir(). Earlier we used glob() to do this.
This code snippet show how to get unique values from a list in Python.
These code snippets show how to create a directory if it doesn’t exist using mkdirs in Python.
These code snippets show how to create a dictionary with alphabets in Python.
This Python snippet converts a png image to ico formatted images and saves it in various sizes.
Let’s use this JSON as an example. I would like to find out if rank key is already in this JSON. To check if a key exists in a JSON, […]
Let’s take the list of dictionaries above as an example. I’d like to sort this list based on the scores value. To do this we can use the sorted() function […]
Let’s take the JSON above as an example. I need the values as a list of dictionaries in Python. This is how I did it.
We can use decorators to calculate the execution time of a function. Here the output is in milliseconds.
In Python, title() function in String method returns a new string whose first letters are capitalized. In short, title() method returns a new title cased string from a string.
To get the length of a string in bytes, first convert the string to Blob and use the size property of blob object to get its length in bytes.
Inverting a dictionary basically means keys and values are swapped i.e keys become values and values become keys.
We can use the slicing in Python to remove the last character from a string in Python.
Source: 30 Seconds of Python
We have already discussed Fisher-Yates algorithm in detail, which is the perfect shuffling algorithm to exist.
We can use bin() to convert a given decimal number into its binary equivalent.