12
Willy Cass
Last seen 2 years ago
Member for 5 years, 8 months, 23 days
Difficulty Normal
Clever solution to the problem. A couple suggestions: I think it would be
clearer if you used different names for the class and instance versions of
the color variable. Even though they are in different name spaces, it can
get confusing. Plus, if __init__ were to change so that the instance
variable
More
Very easy to understand code. Follows the recommended design pattern
perfectly.
More
Good job. I noticed a few things:
1) People don't usually predeclare their variables in python. In cases
where you want to add to a list and start with an empty one, it is usually
clearer to set up the empty list immediately before the list.
2) If you're going to use NumPy, why convert matrix to an
More
Clear even though it uses a nested list comprehension. Might consider
formatting on multiple lines to keep less than 80 characters and increase
clarity.
More
The for ... else syntax isn't really doing anything useful here. There is
no break statement in the for loop, so the else block will always execute.
Your scheme for storing fonts and text in the same variable is also fairly
convoluted. I would take a look at the memento design pattern recommended
in
More
It's not clear to me why this answer works. Each lamp should have its own
state, so that light_iter is specific to each Lamp instance. Here though,
with the use of the global keyword it seems that it is not. In the test
code below the solution, I would think that it would fail when confronted
with t
More
Great solution! I love that you use the dictionary to create a circular
list. I can think of a problem I did recently where this pattern would
really have helped. Great job!
More
Great, simple solution. A couple things you might consider:
-You could make lights a class variable (define it inside the class but
outside a method), as it is shared by all instances of the class. You can
still refer to it as self.lights
-You could consider changing the name of getState to _getStat
More
Note that popping from a list and adding it to the front like this is very inefficient. The entire list needs to be rewritten in memory. In this case it’s a nonissue, but this can be a big slowdown if the list is big or if the method gets called many times. Also, it appears the state() method is not
More
Good answer. Would recommend more descriptive variable names: start, end
rather than s, e.
More
The way that you save the text as the text.show output and don't separately
maintain the font would break in certain cases. For instance, if you saved
the text with a font, restored the saved version, then added more text, the
font would be in the middle of the text.
More
Simple, direct numpy solution. Technically should be in the 3rd party
category
More
Really like that you put the regrex split up in a comment with explanations.
More
Your use of comprehensions makes the code very compact, but I'm having
trouble understanding how some of it works. Particularly line 12. Do you
mind explaining it?
More
Looks good. The first part is a bit confusing - it might be simpler to just check for a number in the for group (with .isdigit()). For the return statement, you could just return the condition directly. Also, I think 'and' is more appropriate than '&' in this case (but both work). See https://stacko
More
Concise, but no reason to assign a lambda. You can use def as a one line statement:
def correct_sentence(t): return t[0].upper() + t[1:] + ('.' if t[-1] != '.' else '')
More
Looks good. Could consider assigning both empty lists at once:
first_command, second_command = [], []
More