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 __bool__() Magic Method

Syntax object.__bool__(self) The Python __bool__() method implements the built-in bool() function. So, when you cal bool(x), Python attempts to call x.__bool__(). If the return value is not a Boolean, Python raises a TypeError. We call this a “Dunder Method” for “Double Underscore Method” (also called “magic method”). To get a list of all dunder methods … Read more

Python Named Tuple Methods

Background The Python’s namedtuple() function is an integral part of the collections library. This function is an immutable container type. Any value, once set, cannot be modified. Access these values via the index or name attribute. The namedtuple() works similar to tuples, however namedtuple() has additional functionality.  This article touches on a few of these … Read more

Python __annotations__ Attribute

Annotations are defined in PEP 3107 allow you to add arbitrary metadata to the parameters and return values of functions. The __annotations__ attribute of a function object stores those annotations in a dictionary mapping function parameters or the return value to the specified annotations. Let’s have a look at a couple of examples next. Parameter … Read more

Python dict.get() Method

Summary: When working with Python dictionaries, in some cases you may want to access a specific value of a certain item, this is where the dict.get() method comes in handy. Definition: Python’s dict.get() method expects a key argument. If the specified key is in the dictionary, the method will output the value associated with the … Read more

Python Dictionary clear()

In this blog post, you’ll learn about the Python Dictionary clear() method. But, before I cover the clear() method I would like to give a brief definition of what a Python Dictionary is. Definition: A Python dictionary data structure is a collection of key-value pairs that are unordered, and are accessed by a key instead … Read more