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 Trends
- 1. Steelers 34.2K posts
- 2. Rodgers 15.1K posts
- 3. Chargers 21.2K posts
- 4. #RHOP 6,011 posts
- 5. Schumer 184K posts
- 6. Herbert 9,367 posts
- 7. #HereWeGo 4,682 posts
- 8. Tim Kaine 9,413 posts
- 9. #ITWelcomeToDerry 2,947 posts
- 10. Resign 86.7K posts
- 11. Durbin 14.2K posts
- 12. Cade Cunningham 4,253 posts
- 13. Cornyn 9,533 posts
- 14. Jaylen Warren 1,442 posts
- 15. #snfonnbc N/A
- 16. Rams 29.3K posts
- 17. #90DayFianceHappilyEverAfter 1,793 posts
- 18. Drummond 2,697 posts
- 19. Dicker Doinker N/A
- 20. Jassi 1,513 posts
Something went wrong.
Something went wrong.