1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
data_list1 = [1, 2, 3, 4, 5]
print("data_list1: {0} {1}".format(type(data_list1), data_list1)) # data_list1: <class 'list'> [1, 2, 3, 4, 5]
data_list2 = []
for item in data_list1:
data_list2.append(item)
print("data_list2: {0} {1}".format(type(data_list2), data_list2)) # data_list2: <class 'list'> [1, 2, 3, 4, 5]
data_list3 = [item for item in data_list1]
print("data_list3: {0} {1}".format(type(data_list3), data_list3)) # data_list3: <class 'list'> [1, 2, 3, 4, 5]
data_list4 = []
for item in data_list1:
if item % 2 ==1:
data_list4.append(item)
print("data_list4: {0} {1}".format(type(data_list4), data_list4)) # data_list4: <class 'list'> [1, 3, 5]
data_list5 = [item for item in data_list1 if item % 2 == 1]
print("data_list5: {0} {1}".format(type(data_list5), data_list5)) # data_list5: <class 'list'> [1, 3, 5]
data_list8 = [x * y for x in data_list1 if x % 2 == 1 for y in data_list1 if y % 2 == 0]
print("data_list8: {0} {1}".format(type(data_list8), data_list8)) # data_list8: <class 'list'> [2, 4, 6, 12, 10, 20]
|
파이썬으로 구현해보는 자식수가 정해지지 않은 트리 (폴더 생성과 삭제) (0) | 2020.04.07 |
---|---|
(Python) Linked List (0) | 2020.02.24 |
(Python) map()과 lambda (0) | 2020.01.12 |
(Python) 2진법 수 출력 (0) | 2020.01.12 |
(Python) 임의의 여러 줄을 입력받아야 하는 문제, EOF (0) | 2020.01.04 |
댓글 영역