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. Reagan 97.1K posts
- 2. #FanCashDropPromotion N/A
- 3. Good Friday 64K posts
- 4. #FridayVibes 4,795 posts
- 5. Happy Friyay 1,503 posts
- 6. #FridayFeeling 2,554 posts
- 7. Core CPI 4,598 posts
- 8. #FursuitFriday 11.9K posts
- 9. Immigration 153K posts
- 10. Tren de Aragua 13.6K posts
- 11. RED Friday 2,699 posts
- 12. U-Haul 8,026 posts
- 13. Oval Office 19.5K posts
- 14. #19YearsOfTaylorSwift N/A
- 15. Finally Friday 5,694 posts
- 16. September CPI 4,310 posts
- 17. Doug Ford 21.6K posts
- 18. Halle 23.2K posts
- 19. Pritzker 94.9K posts
- 20. Happy Friday Everyone 5,534 posts
Something went wrong.
Something went wrong.