40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
It's nice and short. I was surprised that even the last line is shorter than 80 characters. :) Good job!
More
Hi,
1. Line 2 is redundant: __tuple__ is iterable.
2. Line 3 and 4 are redundant: `return ','.join(x).replace('right', 'left')`
Regards,
suic
More
Hi,
1. _issufix()_ is redundant see [_str.endswith()_](https://docs.python.org/3.5/library/stdtypes.html?highlight=str.endswith#str.endswith)
2. `is not` and `!=` don't do the same thing (look at [this](https://docs.python.org/3.5/library/stdtypes.html#comparisons))
3. Instead of:
if word1 is
More
Hi,
1. look at the _sum()_ builtin:
sum(int(digit) for digit in xnorm)
2. In fact, you just need to count the number of "1" in xnorm, therefore:
return bin(n^m).count('1')
More
Hi,
1. this is quite inefficient as __str__ is immutable.
2. Look at negative indices. For non-empty string/list/tuple... `seq[:len(seq)-1] = seq[-1]`.
3. Look at _str.join()_.
More
Hi,
1. You could write:
matchstring = ",".join(matchlist)
# instead of:
matchesstring = ""
for match in matcheslist:
matchesstring = matchesstring + match + ","
matchesstring = matchesstring[:len(matchesstring)-1]
2. Look at __set__ built-in type and set operations:
More
Hi, to clarify my thumbs downs:
First of all: What's creative in this? There's so much redundancy and unnecessary code.
E. g.:
1. Print statements.
2. The last if: return fword == sword.
3. The fword and sword variable:
return sorted(' '.join(first_word.upper()).split()) == sorted(' '
More
Hi,
1. __str__ is iterable => line 3 is redundant.
2. You could write `r *= i` instead of `r = i*r`.
3. `c` is redundant. You can use the list comprehension in for loop on line 6.
4. You could also solve it using _functools.reduce()_.
More
Hi, the `if...else...` is redundant:
return any(...) and any(...) and ... # is enough
More
Hi,
those `bool()` aren't necessary. You could write:
return bool(len(data) >= 10 and num.search(data) and upper.search(data) and lower.search(data))
# or even:
return len(data) >= 10 and all(x.search(data) for x in (num, lower, upper))
More
Hi,
1. All `== True` checks are redundant.
2. All `else` branches are redundant.
3. Finally: When you use _any()_ with `and` or _all()_ all the `if`s are redundant.
Your code after step 2.:
def checkio(data):
if len(data) >= 10 :
if any(c.islower() for c in data):
if
More
What about:
def checkio(*args):
if not args:
return 0
return max(args) - min(args)
More
Hi, that `else` branch is redundant.
This is enough:
~~~~
def verify_anagrams(first_word, second_word):
first = first_word.replace(" ", "").lower()
second = second_word.replace(" ", "").lower()
for x in first:
if first.count(x) != second.count(x):
return False
More
A bit :)
1. Intstead of lines 7-9: `return "".join(result) == 'abcd...z'`
2. Look at [_sorted()_](https://docs.python.org/3/library/functions.html?highlight=sorted#sorted). It takes any iterable including __set__.
Refactored:
~~~~
import re
from string import ascii_lowercase
def check_pangram(t
More