# "List Comprehensions" Exercise

## Prerequisites

* [Lists](/intro-to-python/notes/python/datatypes/lists.md)

## Learning Objectives

* Demystify the incredible powers of Python list comprehensions, a powerful data-processing technique
* Practice performing mapping and filtering operations on Python lists

## Setup

Create a new Python script called something like "total\_comprehension.py" somewhere on your computer, perhaps your Desktop.

Open that file with your text editor and place inside the following contents:

```bash
# total_comprehension.py

my_numbers = [1, 2, 3, 4, 5, 6, 7]
print("--------------")
print("ORIGINAL LIST:", my_numbers)

print("--------------")
print("TOTAL COMPREHENSION...")

# TODO: write python code here
```

From within your "base" environment, or any other Anaconda virtual environment, run the script:

```bash
python total_comprehension.py
```

## Instructions

Write Python code in the "total\_comprehension.py" file which will use the filtering and mapping capabilities of list comprehensions to transform the provided list (i.e. `my_numbers`) in each of the following ways:

* Use mapping capabilities to multiply each number by 100 (e.g. `[100, 200, 300, 400, 500, 600, 700]`)
* Use filtering capabilities to return only the numbers greater than three (e.g. `[4, 5, 6, 7]`)
* Use filtering capabilities to return only the numbers greater than eight (e.g. `[]`)
* Use mapping and filtering capabilities to return only the numbers greater than three, each multiplied by 100 (e.g. `[400, 500, 600, 700]`)

Example final output:

```
--------------
ORIGINAL LIST: [1, 2, 3, 4, 5, 6, 7]
--------------
TOTAL COMPREHENSION...
--------------
MAPPED LIST: [100, 200, 300, 400, 500, 600, 700]
--------------
FILTERED LIST W/ MATCHES: [4, 5, 6, 7]
--------------
FILTERED LIST W/O MATCHES: []
--------------
MAPPED AND FILTERED LIST: [400, 500, 600, 700]
```

## [Solution](https://github.com/prof-rossetti/intro-to-python/tree/f09f436ca11c0a9d85f2e02ce9726af7b60bf3e5/exercises/list-comprehensions/solutions.py)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://prof-rossetti.gitbook.io/intro-to-python/exercises/list-comprehensions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
