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