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. Good Sunday 59.2K posts
- 2. #sundayvibes 5,051 posts
- 3. Full PPR N/A
- 4. #SB19FastZoneConcert 151K posts
- 5. #SundayFunday N/A
- 6. #FrancisLibiran 166K posts
- 7. Cambodia 34.8K posts
- 8. #sundaymotivation 2,279 posts
- 9. Malaysia 154K posts
- 10. Barcelona 139K posts
- 11. Blessed Sunday 19K posts
- 12. HAN SOLO OST OUT NOW 13.9K posts
- 13. Real Madrid 135K posts
- 14. Gronk 2,085 posts
- 15. Barca 83.2K posts
- 16. Troy Franklin N/A
- 17. US and China 20.8K posts
- 18. Ireland 105K posts
- 19. Pavia 3,612 posts
- 20. Jamaica 32.6K posts
Something went wrong.
Something went wrong.