Back to Lesson
Comprehending Functions
Prevent duplicated processing cycles utilizing inline assignment limits mapping list structures.
Instructions
- Given elements dataset.
records = [2, 4, -1, 8, 0] - Imagine callinghappens frequently.
computation = (x * 2) + 1 - Inside a list comprehension: extract only values where the calculated computation evaluates natively to > 0. Store and retain ONLY this output computed metric result.
- Normally this requires calling computation explicitly twice! But leveraging, write
walrus. Print the return sequence.[processed for x in records if (processed := (x * 2) + 1) > 0]
main.py
main.py
Ctrl + Enter