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. Halloween 2.99M posts
- 2. #DoorDashTradeorTreat 1,590 posts
- 3. #sweepstakes 2,682 posts
- 4. #smackoff 2,051 posts
- 5. #SwapSilently 8,562 posts
- 6. Disney 98K posts
- 7. ESPN 80.8K posts
- 8. Jessica Lange 38.6K posts
- 9. YouTube TV 81K posts
- 10. Hulu 23.2K posts
- 11. Monangai 1,415 posts
- 12. Trick or Treat 445K posts
- 13. Candy 250K posts
- 14. Coven 12.2K posts
- 15. YTTV 2,515 posts
- 16. Julia Fox 2,183 posts
- 17. Fubo 4,032 posts
- 18. Mark in Hollywood N/A
- 19. Ridiculousness 6,622 posts
- 20. #jimromeonx N/A
Something went wrong.
Something went wrong.
