PYTHON Study Guide - List Comprehension

44 views3 pages
25 May 2023
Course
Professor

Document Summary

8. 3 - mapping and filtering lists | intro to python. Mapping and transforming items in a list with. When working with lists in spreadsheet software, we can perform mapping or transformation operations on each item in the list. This involves changing each item in the same way, such as multiplying each number by 100. In python, we can perform this operation using a loop and storing the transformed values in a new variable for later use. Let"s say we have a list of numbers: nums = [2, 4, 6, 8, 10] To transform each number by multiplying it by 100, we can use a loop: new_nums = []for n in nums: transformed_num = n * This will print the transformed version of each number and store them in the new_nums list for later use. Filtering a list involves selecting a subset of items that match a certain condition.