Pythonあるある:たぷるになちゃうよ

1 a = 1,

知ってるってば。FAQ だもの。

変更前のほにゃらら
1 def fun(s):
2     if not s.startswith("_"):
3         return s
4 
5 lst = ["abc", "_hij"]
6 d = {
7     "v1": fun(lst[0]),  # v1
8     "v2": fun(lst[1]),  # v2
9 }
変更してみたくなったらら
 1 def fun(s):
 2     if not s.startswith("_"):
 3         return s
 4 
 5 lst = ["abc", "_hij"]
 6 d = {}
 7 v1 = fun(lst[0]),  # v1
 8 if v1:
 9     d["v1"] = v1
10 v2 = fun(lst[1]),  # v2
11 if v2:
12     d["v2"] = v2