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. #GrandEgyptianMuseum 26.6K posts
- 2. #capcutlovers N/A
- 3. Good Saturday 14.2K posts
- 4. Game 7 76.9K posts
- 5. Happy New Month 189K posts
- 6. jungkook 817K posts
- 7. Nigeria 436K posts
- 8. #RUNSEOKJIN_epTOUR_ENCORE 376K posts
- 9. Kawhi 8,638 posts
- 10. vmin 5,139 posts
- 11. GenG 12.6K posts
- 12. #Jin_TOUR_ENCORE 324K posts
- 13. Ja Morant 6,031 posts
- 14. Barger 6,189 posts
- 15. Shirley Temple N/A
- 16. Glasnow 6,917 posts
- 17. Tinubu 48.1K posts
- 18. Justin Dean 2,732 posts
- 19. Halloween 2025 194K posts
- 20. Merry Christmas 10.8K posts
Something went wrong.
Something went wrong.