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