25
Last seen 6 days ago
Member for 2 years, 11 months, 6 days
Difficulty Normal
Well, that's no ordinary rabbit. That's the most foul, cruel, and bad-tempered rodent you ever set eyes on.
- Tim the Enchanter on the Rabbit of Caerbannog
(Monty Python and the Holy Grail)
Nice concise solution, but according to PEP8 the use of an assignment statement that binds a lambda expression directly to an identifier is discouraged.
More
Nice concise solution, but in my opinion using
args
instead of
[i for i in args]
should do the same work.
More
I'm sorry to inform you, but your code doesn't work correctly.
The following call
power_plants({('A', 'B'), ('B', 'X'), ('X', 'C'), ('C', 'D'), ('a', 'b'), ('b', 'X'), ('X', 'c'), ('c', 'x'), ('x', 'e'), ('1', 'x'), ('x', '2')}, [2, 1])
should return
{'X': 2, 'x': 1}
but your code retur
More
It is unnecessary to create so many containers. You can replace the beginning of the code with:
text = text.lower()
dic = dict(map(lambda x: (x, text.count(x)), string.ascii_lowercase))
More
Nice use of itertools.combinations.
Note that you can use
any(a.endswith(b) or b.endswith(a) for ...)
to achieve same thing as
sum(1 for ... if a.endsiwth(b) or b.endswith(a)) > 0
.
More
A clean and concise solution, but I would avoid using except without defining the type of an exception. When used in a larger project, such constructs can hide important exceptions.
More
In my opinion, this isn't such a good solution. One rule of programming is "do not repeat a code" because such a code is less maintainable and leads to bugs. In this case, there are many "if" and "while" blocks that differ only in literals. This could be repaired, for example, by storing values from
More
I like that you used endswith. It makes it legible.
Also instead of creating a list, you can remove the square brackets and have a [generator expression](https://docs.python.org/3/reference/expressions.html#generator-expressions).
More
pop(0) of the list container costs O(n) according to the documentation. I rather recommend passing reverse=True to sorted function and use sorted_lst.pop() that has the cost of O(1).
More
Nice concise solution. Also if you use
map(int, str(number))
instead of
str(number)
then you don't have to deal with conversions to int in the rest.
More