Skip to content

Conversation

@Satorien
Copy link
Owner

## Step 3. Final Solution

- 再帰での実装を練習
- List_A += List_Bを関数内関数で行うとエラー
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nonlocal List_A がいります。
+= は iadd が定義されていれば iadd なければ add を使って足し算と代入をするという仕組みなので参照先を変更する可能性があるので必要です。

近い話としては、このあたり。
https://docs.google.com/document/d/11HV35ADPo9QxJOpJQ24FcZvtvioli770WWdZZDaLOfg/edit?tab=t.0#heading=h.jwt99kks0w2

for subset in all_subsets])
if index_to_add + 1 < len(nums):
add_subsets(index_to_add + 1)
all_subsets = [[]]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inner function 内で使用されている変数が、 inner function より後に定義されていると、変数の定義を探すために上下に目線が移動します。これは読み手にとってやや煩わしく感じます。 inner function の中で使用する変数は、 inner function より前に定義することをお勧めします。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

確かにそうですね、そうします

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants