4.2. List

A list is a data structure used to store an ordered collection of elements, widely used in various programming and data management tasks.

Common List Formats

  • One-dimensional list (single-layer list) example: [1, 2, 3, 4, 5], contains a single level of elements, all elements are at the same level.
  • Two-dimensional list (nested list) example: [[1, 2], [3, 4], [5, 6]], each element in the list is itself a list, forming a matrix or table structure.
  • List of dictionaries, example: [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}], each element in the list is a dictionary, commonly used to store structured data, such as database records.
  • Dictionary of lists, example: {"fruits": ["apple", "banana"], "vegetables": ["carrot", "spinach"]}, the values of the dictionary are lists, commonly used for categorizing stored data.

Image

In this example, the data structure output by the database belongs to the list of dictionaries.

Image

results matching ""

    No results matching ""