컴프리헨션은 하나 이상의 이터레이터로부터 파이썬의 자료구졸르 만드는 컴팩트한 방법
>>> number_list = [number for number in range(1, 6)]
>>> number_list
[1, 2, 3, 4, 5]
>>> number_list = [number-1 for number in range(1, 6)]
>>> number_list
[0, 1, 2, 3, 4]
>>> number_list = [number for number in range(1, 6) if number % 2 ==0]
>>> number_list
[2, 4]
이중 for문을 보면..
>>> rows = range(1, 4)
>>> cols = range(1, 3)
>>> for row in rows:
... for col in cols:
... print(row, col)
...
1 1
1 2
2 1
2 2
3 1
3 2
>>>
>>> cels = [(row, col) for row in rows for col in cols]
>>> cels
[(1, 1), (1, 2), (2, 1), (2, 2), (3, 1), (3, 2)]
>>> word = 'letters'
>>> letter_counts = {letter: word.count(letter) for letter in word}
>>> letter_counts
{'l': 1, 'e': 2, 't': 2, 'r': 1, 's': 1}
>>> ss = {number for number in range(1, 6) if number % 3 == 1}
>>> ss
{1, 4}