22
Last seen 5 years ago
Member for 8 years, 4 months
Difficulty Normal
Would like to receive comments/critics of my published solutions.
Line 15: no need to create a special function to return negation, just use Python's:
return (not x) or y
More
Lines 6 and 7 are not needed. Also, line 4 can be written just like:
if znak.isupper():
More
Line 30: rather than use string concatenation, using format is preferred:
def __repr__(self):
return 'Building({}, {}, {}, {}, {})'.format(
self.south, self.west, self.width_WE, self.width_NS, self.height)
More
1. collections.deque is more suitable than list for popping and inserting on different sides...
2. ...and if you choose deque, you can skip popping and inserting all together, by using deque.rotate
More
Line 27: rather than use string concatenation, using format is preferred:
def __repr__(self):
return 'Building({}, {}, {}, {}, {})'.format(
self.south, self.west, self.width_WE, self.width_NS, self.height)
More
Changed the line 8 to:
neighbours = sum(sum(hood) for hood in neighbourhood)
since @veky said in a recent comment that sum is "clearer, faster and more consistent with that subtraction later" than count.
More
Your first line could be written as:
stripped = [c.lower() for c in text if c.isalpha()]
More
Lines 5-8 can be written simply as:
constraint = min(capacity, number)
Lines 12-18 could be simplified by using list comprehension:
sides_to_paint = [i for i in range(number)] * 2
(This is a random review - sorry if this has already been mentioned)
More
On line 13, more pythonic way would be the thing you did in line 8:
return not stack
More
In your last line, there's no need for if-else, just have it like this:
return prepared(first_word) == prepared(second_word)
More
Line 23: rather than use string concatenation, using format is preferred:
def __repr__(self):
return 'Building({}, {}, {}, {}, {})'.format(
self.south, self.west, self.width_WE, self.width_NS, self.height)
More
Lines 4-11 could be replaced with:
if i in '({[':
lastopen.append(i)
Lines 30-33 could be replaced with:
return not lastopen # the same as: return len(lastopen) == 0
More
Lines 2-4 changed to:
points = {point for pair in connections for point in pair}
More
1. You import itertools and you don't use it
2. No need for if-else in line 3, you can just return it like this:
return sorted(first_word.lower().replace(" ", "")) == sorted(second_word.lower().replace(" ", ""))
More
Line 2: you can create list just by: l = []
Lines 8 and 10: good job knowing integer other than 0 is 'truish' (if len(l)), but you can similarly just check if the list is not empty by: "if l", no need for 'len'.
More