[PYTHON] List comprehension

Summarize the content notation of python. For myself for learning.

    1. Comprehension notation Write what was written separately for processing and for statement in this way as in the last line. Describe the process you want to perform before the for statement. zenified-code (4).png
    1. How to write comprehension notation using if statement In the comprehension notation, if you want to use an if statement, write it after the part you want to use. Note that in the case of a statement that also includes else, both must be written before the for statement. zenified-code (1).png
    1. Let's make a two-dimensional list one-dimensional. This description contains two for statements, but since this execution is executed from the beginning, it will be described later. Unless it is nested, it will be expanded in order zenified-code (2).png
  1. Nested inclusion notation. This comprehension is nested. If it is nested, in this figure, it is executed from for i in range (4) and the process [row [i] for row in matrix] is performed. zenified-code (3).png Also, the zip () function allows you to process multiple values ​​at once.

  2. Dictionary type comprehension The dictionary-type comprehension covers the whole with curly braces. The description of only the if statement is described afterwards. When describing both if and else, describe with a prefix. Since it is a dictionary type, write a judgment formula for both key and value. There is also a way to write using zip as described later. You can also describe the contents of the set by writing without a colon. naihou6.png

Recommended Posts

List comprehension
List comprehension
Python> Comprehension / Comprehension> List comprehension
Note: List comprehension
Python Exercise 2 --List Comprehension
FizzBuzz in list comprehension
Python list comprehension speed
Not just list comprehension
Quicksort 2 | Easy list comprehension
Python comprehension
Comprehension notation
linked list
Python comprehension
Judgment of if by list comprehension
Set comprehension
Join list
[Python] list
Comprehension notation
Python basic operation 1st: List comprehension notation
Python comprehension (list and generator expressions) [additional]
Linux command list
About python comprehension
filter vs comprehension
Python basics: list
Color code list
List type, tuple type 2
[Introduction to Udemy Python3 + Application] 60. List comprehension notation
list and sum
List type, tuple type
list and numpy
List AWS ami
Python list manipulation
List reverse operation
Let's do various things using Python's list comprehension notation
list comprehension because operator.methodcaller cannot be used in python 2.5
Python3 comprehension (List, dictionary) that I have seen somewhere