Category Python List

Python Empty List: How to Check It

Python Empty List: How to Check It

A condition can tell you whether a Python list has items. Python conditions use an object’s truth value, and empty lists are false. This article shows how to check whether a list is empty and how to handle None when…

How to Square in Python: List Values

How to Square in Python: List Values

If you have numbers in a Python list, you can make a corresponding list of their squares. Squaring multiplies each number by itself, and a list comprehension collects those results in a new list. I’ll show how to build that…

How to Use Index in Python

How to Use Index in Python

Working with Python data often means reading a known position or finding where a value appears. Indexing uses square brackets to read by position, and index() searches for a matching value. This article shows how those operations differ and how…

How to Sort a Python List

How to Sort a Python List

When a list’s values are out of order, sorting puts them in the order Python compares them. Python’s list.sort() changes the list itself, while sorted() returns a new sorted list and leaves the source unchanged. I’ll show how to sort…

Convert List to JSON in Python

Convert List to JSON in Python

Saving Python list values for another program means putting them in a format it can read. JSON is a text format for values, and Python’s json module encodes a list as an array. This article shows how to write the…

Iterate Through a List in Python

Iterate Through a List in Python

Matching each name with its score means using the values at the same positions in both lists. Python’s zip() lets a loop process values from corresponding positions together. I’ll show how to choose a loop for the information each pass…