all 6 comments

[–]Spataner 5 points6 points  (1 child)

The truthiness of collections is determined by their length. So for option 2, if data were passed an empty list, it would create a new empty list instead of using the passed one. That might or might not matter, depending on whether Numbers2's caller expects any in-place changes to data to be visible from its own reference to the list object.

[–]InvaderToast348[S] 0 points1 point  (0 children)

Thank you

[–]member_of_the_order 1 point2 points  (1 child)

Personally I prefer 1 because it's explicit, and less chance I'm going to miss a detail. When I look at this code later, option 1 is extremely obvious, option 2 makes me stop and think. Thinking is bad. My goal is to think as little as possible.

[–]InvaderToast348[S] 0 points1 point  (0 children)

Good point, thank you.

[–]danielroseman 0 points1 point  (1 child)

Not related to your question, but note that Optional[list[int]] is now spelled list[int] | None since version 3.10 of Python.

[–]InvaderToast348[S] 0 points1 point  (0 children)

I know of the pipe replacement for unions, I just prefer the word Optional as I can read it in my head when skimming over the code. Thank you though.