Level 10 : What does the following nested list comprehension do?


matrix = [[1, 2], [3, 4], [5, 6]]
flat = [num for sublist in matrix for num in sublist]
print(flat)

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