0% completed
Is there a specific reason why you used neighbors.extend() for a deque rather th...
Richard Yuan
Aug 5, 2022
Is there a specific reason why you used neighbors.extend() for a deque rather than neighbors.append()? The iterable only contains a single tuple in this case.
0
0
Comments
Design Gurus3 years ago
You are right, Append() is more appropriate when adding one element.
Unless, we want to combine all these 'appends' into one single statement. For better readability, we put them in multiple lines.
BTW, which one looks easier to read?
-> neighbors.extend([(row + 1,...
Richard Yuan3 years ago
I see your point about how the bracket can make identifying missing closing brackets/parentheses easier to identify. Personally, I think neighbors.append((row + 1, col)) will be easier to read since we have 1 less pair of [] to type out with append() compared to extend...
Richard Yuan3 years ago
I think it makes sense for consistency that if someone initializes their deque with the cell passed in to use extend() since the format is similar:
neighbors = deque([(x, y)]) ... neighbors.extend([(row + 1, col)])
In contrast to:
neighbors = deque() neighbors.append...
On this page