Computer Science

Python ord() Function

The Python ord() function takes a character (=string of length one) as an input and returns the Unicode number of this character. For example, ord(‘a’) returns the Unicode number 97. The inverse function of ord() is the chr() function, so chr(ord(‘a’)) returns the original character ‘a’. Here are three examples of passed Unicode characters transformed …

Python ord() Function Read More »

They Use These 15+ Python Interview Questions To Fail You … (And What You Can Do About It)

Fear Your Coding Interview? This article shows you how to make your coding interview a success. General Tips to Prepare Your Interview Watch Google Interview tips. Read Prof. Philip Guo’s tips. Practice coding in Google Docs. Don’t use a code highlighting editor for your training time. Solve at least 50+ code puzzles. And most importantly: …

They Use These 15+ Python Interview Questions To Fail You … (And What You Can Do About It) Read More »

How to Compare Each Element of a Numpy Array Against a Value?

To compare each element of a NumPy array arr against the scalar x using any of the greater (>), greater equal (>=), smaller (<), smaller equal (<=), or equal (==) operators, use the broadcasting feature with the array as one operand and the scalar as another operand. For example, the greater comparison arr > x …

How to Compare Each Element of a Numpy Array Against a Value? Read More »

Python min() — A Simple Illustrated Guide

The min() function returns the minimum of the provided arguments. As arguments, you can either pass a number of comma-separated values, or a single iterable. An optional key function argument allows you to customize the calculation of the minimum by explicitly defining the weight of each value in the iterable that is used as a …

Python min() — A Simple Illustrated Guide Read More »

Python max() — A Simple Illustrated Guide

The max() function returns the maximum of the provided arguments. You can pass either an arbitrary number of values, comma-separated, or an iterable as arguments. An optional key function argument allows you to customize the calculation of the maximum by explicitly defining the weight of each value in the iterable that is used as a …

Python max() — A Simple Illustrated Guide Read More »

What’s the Standard Way to Check for Type in Python?

Problem: What is the best way to check whether a given object is of a given type? For example, if you have a variable object, how to check if it’s a string? Check with Subclasses Solution: To check if an object is an instance of str or any of its subclasses, use isinstance: Note that …

What’s the Standard Way to Check for Type in Python? Read More »

How to Create a Sequence of Evenly Spaced Values [Vanilla Python & Numpy Linspace]

Problem: How to create a sequence of evenly-spaced values Using pure, vanilla Python, and Using NumPy’s linspace() method. Example: Given three arguments: start=10, stop=20, number_of_values=11. How do you create a sequence of 11 values x0, x1, …, x10 where two subsequent values xi and x(i-1) have the same distance for all i in {0, …, …

How to Create a Sequence of Evenly Spaced Values [Vanilla Python & Numpy Linspace] Read More »