Python

Rotate an Array K Times in Python

The challenge Given an array, rotate the array to the right by k steps, where k is non-negative. Example 1: Input: nums = [1,2,3,4,5,6,7], k = 3 Output: [5,6,7,1,2,3,4]… Read More »Rotate an Array K Times in Python

Python Splices reimplemented in Java

Python has a fantastic feature called slices. It allows you to work with a list, set or string by it’s index items. E.g.: You can… Read More »Python Splices reimplemented in Java

Solving Two Sum in Python

The challenge Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each… Read More »Solving Two Sum in Python

Get the Next Small Integer in Python

The challenge Write a function: def solution(A) that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does… Read More »Get the Next Small Integer in Python

HashMaps (aka: Dictionaries) in Python

Introduction Java has a built-in called HashMap. It allows you to store and very quickly retrieve key value pairs. In Python, this is called a… Read More »HashMaps (aka: Dictionaries) in Python

Palindrome Partitioning in Python

The problem Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s. Example: Input: “aab” Output: [… Read More »Palindrome Partitioning in Python

Best Time to Buy and Sell Stock with Python

The problem Say you have an array prices for which the ith element is the price of a given stock on day i. Design an algorithm to find the maximum… Read More »Best Time to Buy and Sell Stock with Python

Self Dividing Numbers using Python

Introduction A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is a self-dividing number because 128 % 1 == 0, 128… Read More »Self Dividing Numbers using Python

How to get the UTC Timestamp in Python

All dates in your server applications should be stored in the UTC timezone. This is because you always want to store time without the offset… Read More »How to get the UTC Timestamp in Python

How to duplicate zeros in place using Python

Given a fixed length array arr of integers, duplicate each occurrence of zero, shifting the remaining elements to the right. Note that elements beyond the length of the… Read More »How to duplicate zeros in place using Python

A Quick Introduction to Asyncio in Python3

Python has never been the best at doing multiple things at the same time. While there are ways to mostly resolve this, such as using… Read More »A Quick Introduction to Asyncio in Python3

How to Measure Execution Time in Google Colab

Google Colab is a fantastic environment to write Python code using Jupyter Notebooks, hosted for free by Google. If you’ve ever used Jupyter Notebooks before,… Read More »How to Measure Execution Time in Google Colab

How to fake a User Agent in Python

A User-Agent is a bunch of text that is sent with every HTTP and HTTPS request. The server processing this request is able to determine… Read More »How to fake a User Agent in Python

Read the bottom n lines of a file in Python

Using Operating System Commands in Python Use the Linux/Mac tail command to provide the data: Creating a Python Only Script Read the whole file into… Read More »Read the bottom n lines of a file in Python

How to make a Python script Pip-installable

As Python developers, we’ve all used pip to install applications, but speaking to other Python developers, it’s not always clear how to make your own… Read More »How to make a Python script Pip-installable