Python Generator Expressions

Short Overview Python Generator Expressions provide an easy-to-read syntax for creating generator objects. They allow you to quickly create an iterable object by using a single line of code. A generator expression is like a list comprehension, but instead of creating a list, it returns an iterator object that produces the values instead of storing … Read more

Python List Find Element

To find an element in a list, Python has the built-in list method index(). You can use it to search for an element and return the index of the element. If the element doesn’t exist in the list, the method will return a ValueError. Syntax: list.index(element) Example: The following example searches the string element ‘Sergey’ … Read more

Python Find in List [Ultimate Guide]

When Google was founded in 1998, Wallstreet investors laughed at their bold vision of finding data efficiently in the web. Very few people actually believed that finding things can be at the heart of a sustainable business — let alone be a long-term challenge worth pursuing. We have learned that searching — and finding — … Read more

Format Integer List to Hex String – Six Pythonic Ways

Problem Formulation 💬 Question: How to create a string of hex digits from a list of integers (0–255) so that each hex digit consists of two digits such as “00”, “01”, …, “fe”, “ff”? Here’s an example input/output pair: In: [0, 1, 2, 3, 255, 254, 253] Out: ‘00010203fffefd’ Method 1: Bytearray The easiest way … Read more

Python Create JSON File

Problem Formulation and Solution Overview This article focuses on working with a JSON file. JSON is an acronym for JavaScript Object Notation. This is a flat-text file formatted based on JavaScript (JS) Syntax. This file is most commonly noted for its ability to transmit data to/from web applications, such as sending/receiving data from a Server/Client … Read more

Python Convert String List to Uppercase

Coding Challenge 🥋 💬 Question: How to convert a list of strings to all uppercase in Python? Here are three examples: [‘hello’, ‘Python’, ‘world’] to [‘HELLO’, ‘PYTHON’, ‘WORLD’] [‘a’, ‘b’, ‘c’] to [‘A’, ‘B’, ‘C’] [‘aa aa’, ‘bb$bb’, ‘cc()cc’] to [‘AA AA’, ‘BB$BB’, ‘CC()CC’] There are multiple great ways to accomplish this coding challenge and … Read more