Mapsfunction
Source: 4-Functions/4.4-Mapsfunction.ipynb
Start here — no coding background needed
What you will learn
Apply the same change to every item in a list.
In simple words
`map` runs a function on each element — like converting every price to include tax.
Write a recipe once, use it many times — functions save repetition.
Easy example — run this first. Change values and press Run again.
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Reference notes (from full bootcamp)
Optional — deeper detail for when you are ready
The map() Function in Python
The map() function applies a given function to all items in an input list (or any other iterable) and returns a map object (an iterator). This is particularly useful for transforming data in a list comprehensively.
Expected (from notebook): 100
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): [1, 4, 9, 16, 25, 36, 49, 64]
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): [1, 4, 9, 16, 25, 36, 49, 64]
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): [5, 7, 9]
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): [1, 2, 3, 4, 5]
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): ['APPLE', 'BANANA', 'CHERRY']
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Expected (from notebook): ['Rish', 'Jack']
Runs in your browser via Pyodide — no server. First run may take a few seconds.
Conclusion
The map() function is a powerful tool for applying transformations to iterable data structures. It can be used with regular functions, lambda functions, and even multiple iterables, providing a versatile approach to data processing in Python. By understanding and utilizing map(), you can write more efficient and readable code.
Practice test — try yourself
Write code, press Check. Wrong answer shows the correct code to copy & run.
You learned "Mapsfunction". Use print() to show: Done: Mapsfunction
Hint: Use one print() with the exact text.