Level 9 : What does the following list comprehension do?


numbers = [1, 2, 3, 4, 5]
squared_even = [n**2 for n in numbers if n % 2 == 0]

Author: KaivalyaG | Tags: list | 1859+ Python FAQs | Share
logical-operation | built-in-function | handling-missing-values-(fillna,-dropna) | library | list-indexing | conditional-statement | boolean-masking | class | decimal | dictionary-comprehensions | head-and-tail | basic | join | class-and-inheritance | defining-functions | built-in | immutability | anchors-(^,-$) | directory-operations | asyncio-module | introduction-to-multiprocessing | descriptors | data-structures | data-type | global-keyword | exponentiation | compute | rollback | list-method | decorator | bitwise | intering | print | min-max-function | gil | touples | return-statement | string-manipulation | installation | namespace | matplotlib | binary | file-handling | class-and-instance-variable | control-statement | error-handling | booleans | managing-directories-with-os-and-shutil | complex | logical-operators | data-type-conversions | dictionary | math | software-design | control-flow | function-and-scope | quantifiers-(*,-+,-?,-{}) | overflow | iterable | deep-copy | heap-memory | logical-operator | integer | encoding | match | fabs-function | __all__-attribute | scientific-notation | floats | memory-management | iterator | string-method | round-function | mapping-function | static-method | binary-operation | condition | choice | sys | sorting-and-ranking | loops | integers | __future__ | class-decorators | pseudocode | max-min | file-handling | set | higher-order-function | multiprocessing | list-slicing | slice | dictionary-methods | goto-function | lambdas | string-slicing | syntax-error | inherit | yield | exception | strings | attribute | file_handling | copy | operations | key-value-pairs | reading:-read(),-readline(),-readlines() | multiple-inheritance | file | built-in-function | datetime.date,-datetime.time,-datetime.datetime | mathematics | application | collections | matrix | operator | classes | sorted | using-lists-as-stacks | destructor | data-structures-in-python | variable | asyncio | id-function | def | thread-synchronization | namedtuple | else-statement | array | conditional-statement | dictionaries | sum() | version | identifier | sets | loop-control | bitwise-operator | while-else-loop | set-operation | bitwise-operator | append | conversion | using-the-threading-module | multithreading | python_version | assignment-operators | call | encapsulation | boolean | polymorphism | string-slicing | aggregating-data-with-functools.reduce() | access-modifier | python-repl | filter | regular-expressions | identity-operator | counter-function | operators | string | methods | while-loop | exception-handling | docstring | string-iteration | type-conversion-and-casting | statement | multiple-except-blocks | mutable | opening-files-(open()) | using-else-and-finally | working-with-temporary-files-using-tempfile | type-conversion | function-argument | thread-safe-data-structures-(queue.queue) | functions | functional-programming | split | built-in-modules | generators-in-python | parameter | round | recursion | default-mutable-argument | constructor | while-loops | method | default-arguments | filtering-and-indexing | tuple | list-join | datetime | pep | reading-and-writing-files | format | invalid-list | lambda | min-function | enumerate() | magic-method | staticmethod | error | syntaxerror | iterators | context-manager | dataframe-and-series-objects | assignment-operator | writing:-write(),-writelines() | list-methods-and-slicing | map-function | async | creating-custom-modules | logical-operator | dicts | overriding-methods | python-django | list-operation | literal-characters-and-special-characters | zip-function | immutable-data-type | tuple-methods | list,-set,-and-dictionary-comprehensions | data-type | string-concatenation | membership-operators-(in,-not-in) | data-types | boolean-and-non-boolean | list-comprehension | conditional-statements | type_conversion | using-os-and-pathlib-modules | using-yield-in-functions | int | list-comprehensions | virtual-environment | python-operators | assert | arithmetic-expression | collection | pandas | for | indexing:-loc-vs-iloc | zfill-function | type-conversion | global | comparison | data_structure | arithmetic-operation | global-variable | design-principle | creating-and-starting-threads | math-copysign | list-mutation | sys-module | working-with-dates-and-times | function | virtual-environment | version-check | lambda-function | command-line-parsing | module | single-inheritance | identity-operator | floating-point-precision | debugging | string-formatting | working-with-file-paths | why-use-multiprocessing-over-threading?-(gil) | reading-and-writing-large-files-efficiently | oop | identity-operators-(is,-is-not) | keyword | list-comprehension | loop | loop-control-statements | global-variable | regex | working-with-binary-files-(rb,-wb) | implementation | mysql | complex-number | test-discovery | objects | python-syntax-and-structure | postfix | multiple-inheritance | list-vs-tuple | while-and-for-loop | feature | else | name-mangling | formal-and-actual-parameter | python-module | joining-and-merging-dataframes | stack | random | center | regular-expression | with-statement | method-overloading | operator-and | numpy | formatting-with-strftime | oops | control-flow | mathematical-function | slicing | tuple-unpacking | lists | time-series-with-pandas | difference-between-threads-and-processes | shallow-copy | counter | benefit | pass | input | zip | walking-through-directories-using-os.walk() | error-handling | data-structure | datatype | syntax-error | class-and-object | comprehension | swapping | sum-function | generator | recurssion | data-structure | introduction-to-threads | matrix-list-comprehension | functional-programming | update | turtle | typeerror | advanced-file-operations | string-formatting | arbitrary-arguments-(*args,-**kwargs) | comment | odd-number | sorting | using-join()-and-is_alive()-methods | generators | introduction-to-python | random-function | package-management | string-method | range | expand-tab | import-method | string-methods | nested-loop | using-map()-for-transformations | lambda-functions | tuples | pickling--unpickling | indexing | raise-statement | operand | escape-operator | inheritance | numeric | syntax | print-statement | input-function | python | thread | exception-handling | init | using-assertions-(assertequal,-assertraises) | raise | precedence-and-associativity | unit-testing | operator-overloading | expression | threading | python-history | parsing-with-strptime | input-function | object-attribute | factorial-function | frozenset | memory | indentation | list | filter-function | precedence | operator-or | __init_subclass__ | interpreter ...