bslatkin / effectivepython

Effective Python: Second Edition — Source Code and Errata for the Book
https://effectivepython.com
2.24k stars 718 forks source link

Item 6: Functions need return statement #118

Closed EricRa closed 4 months ago

EricRa commented 8 months ago

I'm not sure if this was intentionally omitted for brevity or not, but the bubble sort functions in Item 6 do not include a return statement needed for the code to function as written.

For example, the bubble_sort function demonstrating swapping of variable values should include a "return a" at the bottom of the function.

KirkSuD commented 5 months ago

The functions sort the list in place, no copy is made, so there's no need to return it. Just like a.sort() & random.shuffle(a). And the example code never uses return value of bubble_sort(), so it's fine.

bslatkin commented 4 months ago

Thank you for the report! I agree with @KirkSuD about why this is fine.