VBAオジサンのらくがき帳

Comprehension

2021-08-07 00:00:00

サンプル

l1 = [1, 2, 3, 4, 5, 6, 7]

l2 = [x * 2 for x in l1]
l2 = [x for x in l1 if x > 3]

l2 = [1, 2, 3]
l3 = [[x, y] for x in l1 for y in l2]

l3 = [[x, y] for x in l1 if x > 3 for y in l2 if y < 3]

s = {x for x in "abcabc"}

d1 = {0: "a", 1: "b", 2: "c", 3: "d", 4: "e"}
d2 = {x: d1[x] for x in range(3) if d1[x] != "b"}