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. Good Wednesday 20.3K posts
- 2. #MAYATVAWARDS2025 494K posts
- 3. Huda 12.8K posts
- 4. Hump Day 8,620 posts
- 5. #NationalCatDay N/A
- 6. #hazbinhotelseason2 13.5K posts
- 7. South Korea 91.3K posts
- 8. Clippers 14.7K posts
- 9. Namjoon 195K posts
- 10. Harden 10.8K posts
- 11. Jay Z 6,622 posts
- 12. Olandria 28K posts
- 13. Tapper 27.8K posts
- 14. Eminem 12.2K posts
- 15. Kawhi 3,823 posts
- 16. #RHOSLC 8,380 posts
- 17. Nvidia 73.1K posts
- 18. Caden 9,134 posts
- 19. Lil Wayne 4,941 posts
- 20. Western Union 12.7K posts
Something went wrong.
Something went wrong.