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

How to Convert a NumPy Array to a Python List? (1D, 2D, 0D)

In this post, we will explore simple methods to convert NumPy arrays to lists. For example, we can utilize the Python function list() or the NumPy array method tolist().Β  Both ways are similar, but there are some differences to consider to choose the right one for each application.  Python Function list() The function list() accepts … 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

6 Ways to Remove Python List Elements

Problem Formulation and Solution Overview This article will show you how 6 ways to remove List elements in Python. To make it more interesting, we have the following running scenario: Suppose you have a Christmas List containing everyone to buy a gift for. Once a gift is purchased, remove this person from the List. Once … 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

Python Convert String List to Lowercase

Coding Challenge πŸ₯‹ πŸ’¬ Question: How to convert a list of strings to all lowercase 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