Python

List Comprehension

green_ne 2021. 1. 3. 00:23

[  표현식  for 요소 in 컬렉션 [ if 조건식 ] ]

list = [ n**2  for n in range(10) 
         if n%3 == 0 ]
list = [ 0, 9, 36, 81 ]

 

위의 표현식은 다음을 요약한 것과 같다.

list = []
for n in range(10):
  if n%3 == 0:
    list.append(n**2)

 

 

 * Comprehension (이해력)

: the ability to understand something. (=understanding)
: full knowledge and understanding of the meaning of something.

 

 

 

 

반응형