40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, what about:
return ','.join(w.replace('right','left') for w in phrases)
# or even:
return ','.join(phrases).replace('right','left')
More
Hi,
1. The last if...else is redundant.
2. _ad_ line 3: __set__ has _set.add()_ method.
3. Lines 4, 5 are redundant because all you should replace is space, as there is the precondition:
> Words contain only ASCII latin letters and whitespaces.
Your code after cleanup:
def verify_anag
More
Hi,
1. That `else:` is redundant.
2. Lines 13-15 should be right after the function definition.
3. Look at _sum()_ and _extended slices_.
More
Hi,
1. Line 5: `if not u: return []`
2. You don't need __Counter__.
3. Look at other solution, which use simple list comprehension.
More
Hi, look at _sum()_ and _generator expressions_:
sum(i in text.lower() for i in words)
More
Hi,
1. Please, forget about semicolons in Python :)
2. Look at _map()_:
l = map(int, str(number))
3. Ad line 4:
l = filter(None, l)
# or even:
l = filter(None, map(int, str(number)))
4. Look at _int.\_\_mul\_\_()_ or _mul()_ from `operator` module:
return reduce(int.
More
Hi, line 2 is redundant as `arg` is iterable, you don't need to convert it to a list.
More
Hi,
1. that last `if...else` is redundant, you can directly return your condition.
2. or you can move that if inside the for loop:
if ...:
for ...:
...
if n and u and l:
return True
return False
More
Hi, this is an overkill:
1. Look at _extended slices_ e. g. `array[::2]`.
2. After some clean-up:
def checkio(array):
if array:
evens = []
for i, v in enumerate(array):
if i % 2 == 0:
evens.append(v)
return sum(evens) * array[-1]
ret
More
Hi,
1. That `for i in text:` is useless.
2. You don't need `[]` in _str.join()_.
3. Look at _filter()_.
More
Hi, I have some comments:
1. To test if array is empty:
if array: # non-empty array is treated as true and empty array as false
...
2. Look at extended slices in python:
array[::2] # gives you the even elements.
3. else branch is redundant.
4. There's a useful function calle
More
Hi, you don't need to import string and you also don't need the letters and asSet variables:
def check_pangram(text):
return len(set(filter(str.islower, text.lower()))) == 26
More
Hi, look at _str.isdigit()_, and generator expression is cleaner in this case than map:
a = "".join("0" if x.isdigit() else "1" for x in command)
More
Hi, this is __not__ pythonic. Some examples:
1.To check if a list or other iterable is empty:
if not array:
return 0
2. Don't use _sum_ as variable name. _sum_ is a useful built-in, which you override this way.
3. Don't use index, where you can iterate
# NO:
for i in len(ar
More
Hi, you don't need the else branch in the first if...else:
if number % 3 == 0:
...
if number % 5 == 0:
...
More