22
Dahlia Ramm
Last seen 1 year ago
Member for 8 years, 1 month, 3 days
Difficulty Normal
+ Line 2 is useless. _args_ is of type tuple and since you do not need to modify the values it contains it makes no sense to change the type to list.
+ line 3:
if len(given_args) > 0: ==TO==> if args: ==> much more pythonic
In another solution you used try - except! Can you think of a way to
More
Line 5:
if word in text.casefold():
This if-statement is inside the for-loop, so text.lower() is called on **every** iteration. Creating a variable like “text_lower” outside of the for-loop and assigning text.lower() to it would be more effective.
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
A bit too complicated!
Why not deleting lines 1 and 11 to 13 and changing line 8 to:
try:
return array[n] ** n
That's lss 4 lines of code and no import and does the same.
More
- bin(number) returns a string ==> no need for type casting
- does it make sence to get rid of the frist 2 characters in the string returned by bin(number)?
will those 2 characters ever effect the result when you use count('1')?
More
smarter would have been to:
- use _max()_ instead of _sorted()_
- use _key=data.count_
- when using _sorted()_, use _[-1]_ instead of reversion
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
Line 3:
Slicing is not really required, coz the represention will ALWAYS start with "0b", which does not affect the result
Line 4:
Casting to String is useless as bin() returns a string.
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
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
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
Nice idea to put line 8 into the if from line 6, as this is the only place where count can increase.
But why do break at line 9? Count equals 3, so return True and get rid of line 12 + 13 + 14 and decrease the indentation level of line 15.
Line 12:
if count >= 3:
can count ever become > 3 ?
More
Same idea as I had, but a bit more complicate.
Line 4 is redundant.
Line 5 to 10 can be compressed to:
try:
return line[:line[:length + 1].rindex(' ')] + '...'
except ValueError:
return '...'
More
and one more time...
Nice!
But why are u using
key = lambda x: abs(x)
instead of
key=abs
More
Line 4:
return sum(x for x in array[::2])*array[-1]
"x for x in" is reduntant.
More
Hmmm, I was expecting something more special, but I should have known better. :D
More
This one is great!
But I don't get why line 2 does not fail on generators.
Usually generators don't have a len attribute and are not subscriptable.
More
Line 4:
if word in text.lower():
This if-statement is inside the for-loop, so text.lower() is called on **every** iteration. Creating a variable like “text_lower” outside of the for-loop and assigning text.lower() to it would be more effective.
More
Turning _data_ into a _set_ would prevent from repeatedly counting equal elements.
More