Iterative vs. Recursive Binary Search Algorithms in Python

In this article, you鈥檒l learn about a basic algorithm, every computer scientist must know: the binary search algorithm. I have drawn the code from my NoStarch programming introductory book Python One-Liners: Applications Binary Search The algorithm has important practical applications in many basic data structures such as sets, trees, dictionaries, bags, bag trees, bag dictionaries, … Read more

Python Nested Multiple Ternary Operators

In which order does the nested ternary operator evaluate its conditions? Short Answer: The nested ternary operator ‘1’ if x else ‘2’ if y else ‘3’ evaluates the condition from left to right, i.e., ‘1’ if x else (‘2’ if y else ‘3’). In short, first condition first! Problem Formulation Given a nested ternary operator … Read more

The Shortest Quicksort Algorithm in Python

Quicksort is not only a popular question in many code interviews 鈥 asked by Google, Facebook, and Amazon 鈥 but also a practical sorting algorithm that is fast, concise, and readable. Because of its beauty, you won鈥檛 find many introductions to algorithms that don鈥檛 discuss the Quicksort algorithm. In this one-liner tutorial, you鈥檒l learn about … Read more

La forma m谩s pit贸nica de comparar dos listas en Python

Problema: Se dan dos listas l1 y l2. Quieres realizar una de las siguientes acciones: 1. Comparaci贸n booleana: comparar las listas por elementos y devolver True si la m茅trica de comparaci贸n devuelve True para todos los pares de elementos y False en caso contrario. 2. Diferencia: encontrar la diferencia entre los elementos de la primera … Read more

C贸mo convertir una lista de enteros en una lista de cadenas en Python

English version of article (English): https://blog.finxter.com/how-to-convert-an-integer-list-to-a-string-list-in-python/ La forma m谩s pit贸nica de convertir una lista de enteros ints en una lista de cadenas es usar el c贸digo de una l铆nea strings = [str(x) for x in ints]. Recorre todos los elementos de la lista ints y convierte cada elemento de la lista x en una cadena … 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? 鈥淎 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

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