22
Dahlia Ramm
Last seen 1 year ago
Member for 8 years, 19 days
Difficulty Normal
Very complicated and lots of redundant expressions.
- Line 12:
a = n
What for? You are not reusing the original value of _n_ anywhere, so why do need a copy of it?
- Line 16:
a, c = a//2, a%2
using _divmod()_ is shorter and clearer...
a, c = divmod(a, 2)
- Line 17 to 18:
More
Maybe a bit too much for this task **but** a great example on what is possible.
This also is the best approach if you ever want to decode a roman numeral to decimal rep.
Just add decode method and your're done.
Great!
More
Cheater!
The taks asked you to **calculate** the return value and not to look it up in a table. :D
More
Hm...
Correct idea but you haven't thought it to the end.
Your `add_food` and `add_drink` methods are **exactly** the same in all the concrete classes, so why do have to enforce yourself to override them in each subclass?
And your `total` method doesn't need an override too. You could simply use
More
Wow, this one is scary!
+ the readability of this is bad
while True:
if flist[len(flist)-1] > 5000: break
else: flist.append(flist[len(flist)-1]+flist[len(flist)-2])
what about this?
while flist[-1] < 5000:
flist.append(flist[-1] + flist[-2])
+ You are
More
Whoo, took me some minutes to figure out how the lamdba works here (thanks to Pythontutor :D)
Really cool!
More
@veky once argued with me, because I was mapping a lambda. He explained that this is a LISPsm!!!
I don't see why using a LISPsm is bad, by **I do agree** that mapping a lambda is not good when an generator expression can do the job:
max(
(len(list(v)) for k, v in groupby(line), default=
More
Calling _filter_, which calls a lambda, which calls _bin()_...
Why not an if statement in the generator?
''.join(chr(c>>1) for c in message if not bin(b).count('1') & 1
More
I would recommend to get rid of line 2 and change line 4 to:
for i in words.split()
this saves a line of code.
Be careful when using str.split(" ") instead of str.split().
More
Turning _data_ into a _set_ would prevent from repeatedly counting equal elements.
More
Never use blank excepts, always make sure to catch specific exceptions instead of all exceptions.
except KeyError:
elements[element] = 1
But in this case it's even better to prevent the raising of KeyErrors, by using _dict.fromkeys()_.
# this guarantees that any string from data
More
Clear!
You can improve your solution by apllying the [EAFP coding style](https://docs.python.org/3/glossary.html#term-eafp).
This means that, instead of explicitly checking if _n_ is a valid index for _array_ you simply assume that it is and in case an Error is raised you catch it...
try:
More
Nice use of the std libs.
Could even be simplified to:
from statistics import mode as most_frequent
:D
More
Learned something new - again!
If I got it wright, using functools.partial() makes most sense if you are actually planning to reuse
the partial object?
More
Yes obvious, but there are two thing I don't like about it...
1. The rule **gcd(a, a) = abs(a)** makes it clear, that repeated values, DO NOT effect the final result.
So turning _args_ into a set, decreases the number of calls to _gcd()_
2. Another problem is that _reduce()_ keeps calling _gcd()
More
Very nice and clear.
Just one small thing: Instead of using this:
wall.strip().split('\n')
it would be more readable and simpler to use `str.split()`:
wall.strip().split('\n')
By default `str.split()` splits at any whitespace character and treats consecutive whitespace characters as a s
More
Line 2:
sections = list(map(list, zip(*wall.split()))) # -> string into transposed list
If you change this to:
sections = list(zip(*wall.split()) # -> string into transposed list
The least one is shorter and easier.
You will get a list of tuples instead a list of lists, but since tuple
More