Python __int__() Magic Method

Syntax object.__int__(x) The Python __int__() method implements the built-in int() function. So, when you call int(x), Python attempts to call x.__int__(). If the return value is not an integer, Python will raise a TypeError. If it’s not implemented, Python attempts to call x.__index__() instead, and only if this is not implemented either, it raises a … Read more

Python Palindromes One-Liner

This one-liner introduces another basic computer science term: palindromes. Similar to anagrams, palindromes are a popular coding interview question. First things first: What is a Palindrome? “A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as madam or racecar or the number 10201.“ [source] … Read more

Python Input/Output – The Clipboard

Over your career as a Data Scientist, there may be instances where you will work with data to/from the system Clipboard. This article shows you how to manipulate this data. Preparation Before any data manipulation can occur, one (1) new library will require installation. The Pandas library enables access to/from a DataFrame. To install this … Read more

Iterative Deepening Depth-First Search (DFS) Algorithm in Python

What is an Iterative Deepening Depth-First Search Algorithm? Continuing our story even further, after introducing graphs and basic graph traversal algorithms, we will refine the Depth-First Search Algorithm by introducing the iterative depth limitation. An iterative deepening depth-search algorithm also traverses a graph by exploring it vertex-by-vertex, but it does it by following the vertical … Read more

Finxter.com Puzzles by Topic

Arithmetic Arithmetic Operations https://app.finxter.com/learn/computer/science/314 Integer Arithmetic https://app.finxter.com/learn/computer/science/381 Python Float Arithmetic https://app.finxter.com/learn/computer/science/320 OOP Basics of OOP https://app.finxter.com/learn/computer/science/527 OOP https://app.finxter.com/learn/computer/science/606 OOP – Representation https://app.finxter.com/learn/computer/science/594 Filter Filter and Recursion https://app.finxter.com/learn/computer/science/493 Set, Lambda, and Filter https://app.finxter.com/learn/computer/science/399 The Filter Function https://app.finxter.com/learn/computer/science/375 DataFrames DataFrames and Datatypes https://app.finxter.com/learn/computer/science/614 DataFrames and Series https://app.finxter.com/learn/computer/science/612 Merging DataFrames https://app.finxter.com/learn/computer/science/621 Add Column To DataFrame https://app.finxter.com/learn/computer/science/616 DataFrame Creation … Read more

Python Pandas Input/Output – Flat File

Over your career as a Pythonista, there may be instances where you will work with Flat Files. This file type is an ASCII character-based file, usually with commas (,) separating the fields. Other common field separators are the following: Semi-colon (;) Tab character (\t) Colon (:) and so on. This article covers the commonly used … Read more

Python __float__() Magic Method

Syntax object.__float__(x) The Python __float__() method implements the built-in float() function. So, when you call float(x), Python attempts to call x.__float__(). If the return value is not a float, Python will raise a TypeError. If x.__float__() is not implemented, Python attempts to call x.__index__() first and only if this is not implemented either, it raises … Read more

Cómo convertir una lista de cadenas en una lista de números en coma flotante (flotantes) en Python

La forma más pitónica de convertir una lista de cadenas en una lista de flotantes es usar una comprensión de listas floats = [float(x) for x in strings]. Recorre todos los elementos de la lista y convierte cada elemento de la lista x en un flotante utilizando la función incorporada float(x). Este artículo muestra las … Read more

Python __index__() Magic Method

Python’s __index__(self) method is called on an object to get its associated integer value. The returned integer is used in slicing or as the basis for the conversion in the built-in functions bin(), hex(), and oct(). The __index__() method is also used as a fallback for int(), float(), and complex() functions when their corresponding magic … Read more

No, Python __oct__() Doesn’t Exist Anymore. Do This Instead!

The Problem TypeError: ‘…’ object cannot be interpreted as an integer If you’re reading this article, chances are that you have been thinking something along those lines: Given a custom class My_Class. You want to override the behavior of the built-in oct(x) function in Python when calling it on a My_Class object x. You know … Read more

No, Python __hex__() Does Not Exist. Do This Instead!

The Problem TypeError: ‘…’ object cannot be interpreted as an integer If you’re reading this article, chances are that you have been thinking something along those lines: Given a custom class My_Class. You want to override the behavior of the built-in hex(x) function in Python when calling it on a My_Class object x. You know … Read more

Python Anagrams in One Line Python

Why Learning about Python Anagrams? A popular question in programming interviews is to create an anagram checker. The interviewer wants to test your knowledge about the basic terminology in computer science, and how good you are at developing your own simple algorithms to solve the problems you are facing. In this article, you’ll learn about … Read more