effectivepython icon indicating copy to clipboard operation
effectivepython copied to clipboard

Item 6: Functions need return statement

Open EricRa opened this issue 2 years ago • 1 comments

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.

EricRa avatar Jan 31 '24 20:01 EricRa

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.

KirkSuD avatar Apr 08 '24 14:04 KirkSuD

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

bslatkin avatar May 31 '24 23:05 bslatkin