Data Structures

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 »

How To Check If a List Is Nested In Python?

Summary: One of the following methods can be used to check if a list is empty :- Method 1: Using isinstance() With any() Method 2: Using isinstance() And len() Methods Within For Loop Problem: Given a list; how to check if it is nested or not? Considering that you have a list such that it is nested at …

How To Check If a List Is Nested In Python? 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 »

Python tuple() — A Simple Guide with Video

Python’s built-in tuple() function creates and returns a new tuple object. When used without an argument, it returns an empty tuple. When used with the optional iterable argument, it initializes the new tuple with the elements in the iterable. Read more about tuples in our full tutorial about Python Tuples. Usage Learn by example! Here …

Python tuple() — A Simple Guide with Video Read More »

Python list() — A Simple Guide with Video

Python’s built-in list() function creates and returns a new list object. When used without an argument, it returns an empty list. When used with the optional iterable argument, it initializes the new list with the elements in the iterable. Read more about lists in our full tutorial about Python Lists. Usage Learn by example! Here …

Python list() — A Simple Guide with Video Read More »

How to Initialize a NumPy Array with Zeros and Ones

Numpy is a popular Python library for data science focusing on linear algebra. In this article, you’ll learn how to initialize your NumPy array. How to Initialize a NumPy Array with Zeros? To initialize your NumPy array with zeros, use the function np.zeros(shape) where shape is a tuple that defines the shape of your desired …

How to Initialize a NumPy Array with Zeros and Ones Read More »