refactoring code before(right side), after(left side) #Python #RefactoringCode context : The functions check if the 'value' can be inserted in a particular position(x, y) in its row or column , in a game of sudoku.
Refactoring: The first if condition checks if the position (x, y) is possible in the board. We observe that it doesn't tell to much directly and have to read the if conditions to understand. So we move it out of function and put it in a lambda function 'in_board'.
Now the code expresses itself and can be reused in other functions too. Second refactoring is of the loop which compares each value in row/column of (x, y) and match it with the value. return False if value is present and true if not present.
This could be refactored by using all builtin function which makes the code more expressive.
United States 趋势
- 1. #TheGamingAwards N/A
- 2. Good Thursday 33.4K posts
- 3. #WeekndTourLeaks N/A
- 4. #TikTokCouplesAreFake N/A
- 5. #thursdaymotivation 2,120 posts
- 6. #ThursdayThoughts 2,035 posts
- 7. Happy Friday Eve N/A
- 8. The Hunger Games 37.9K posts
- 9. Reaping 35.6K posts
- 10. Crockett 66.4K posts
- 11. FAYE SHINE IN ARMANI 173K posts
- 12. Nnamdi Kanu 87.9K posts
- 13. FEMA 92.1K posts
- 14. Ray Dalio 1,776 posts
- 15. FREE HAT 2,208 posts
- 16. Unemployment 26.1K posts
- 17. The 2024 90.9K posts
- 18. The CDC 14.8K posts
- 19. Wordle 1,615 X N/A
- 20. LINGORM CH3 CALENDAR SIGN 953K posts
Something went wrong.
Something went wrong.