40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
It's not a bad solution, but it can be improved:
1. [Set](https://docs.python.org/3/library/stdtypes.html?highlight=intersection#set-types-set-frozenset) is more suitable for this task.
2. You could replace this:
c = []
for i in a:
for j in b:
if i==j: c.append(i
More
Hi, you could write it also this way:
return bool(re.compile('.*?[a-zA-Z]+ [a-zA-Z]+ [a-zA-Z]+.*?').match(words)) # :)
More
Hi, you don't the _True ... if ... else False_ as your condition is already a boolean value so:
return len(set([e for e in text.lower() if e.isalpha()])) == 26
More
Hi,
you could write `if not array: return 0`.
Look at [this](https://docs.python.org/3/library/stdtypes.html#truth-value-testing) and try it in REPL:
>>> bool([])
False
More
Hi, I have a few comments:
1. Line 11 is useless as it's never reached because it returns on line 10.
2. Inconsistent indentation: Lines 8, 9.
3. Look at slices and sum in Python e. g. lines 7-9 you could write like this:
b = sum(array[::2])
4. Look at negative indexes (they indexes from end
More
Hi, you can shorten it using _any()_:
return any(a.endswith(b) for a, b in permutations(words_set, 2))
More
Hi, why try...except? You can easily handle it by _if_ or _and_. E. g.:
if array:
...
else:
return 0
More
Hi, you could shorten this and eliminate one branch:
if word != word1 and word1.endswith(word):
return True
You could also use [_any()_](https://docs.python.org/3.5/library/functions.html?highlight=any#any) for this.
More
Hi, so many zeros :)
Btw.:
g,v = 0,0
...
s1 = 0
i,j = 0,0
s2 = 0
# is the same as:
g, v, i, j, s1, s2 = 6 * [0]
More
Hi, two things:
1. __list__ is redundant as numbers_array is iterable.
2. in this case you can replace lambda x: abs(x) with abs
More
Hi,
1. Line 2: _if else_ is unnecessary, and in python you could write it like this:
return (0 <= row < height) and (0 <= col < width) and grid[row][col]
2. Line 10: a) _if ... else_ is unnecessary b) _x != 0 or y != 0_ is the same as _x or y_. So you could write this:
sum +=
More
Hi,
1. != None is unnecessary.
2. There's three times the same pattern. Consider using _all_ and _list comprehension_ or _generator expression_ instead.
More
Hi,
1. This is an anti-pattern:
if condition:
return False
else:
return True
# You could write:
return not contdition
2. `True == 1` and `False == 0` so:
return not((not upp) or (not low) or (not dig))
# or shorter:
return upp and low and dig
More
Hi, I have a few comments:
1. _bin()_ returns __str__ so _str()_ is redundant.
2. Look at `^` operator or _set.symmetric_difference()_ method ([docs](https://docs.python.org/3/library/stdtypes.html#set.symmetric_difference)).
3. `range(20) == range(0, 20)`
4. Line 12: `hem_dis += 1`
5. You could us
More
Hi,
1. _sum()_ is a built-in function, don't redefine it, e. g. `sum(array[::2])`.
2. What's the point of `[0:]` `table = array[0:][::2]`? `array[::2]` is enough.
3. For non-empty array: `array[len(array)-1] == array[-1]`.
More
Hi,
1. Look at _filter()_ and _str.join()_.
2. As __str__ is an immutable type in Python, it's not the best candidate to accumulate values.
3. You could write `i += 1`.
More
Hi, this:
if text.lower().find(s.lower()) != -1:
is not Pythonic. It's more like _Javascript_ than Python.
It should be:
if s.lower() in text.lower():
More
Hi, lines 12, 15, 18 are redundant, as
1. `"Fizz Buzz"`, `"Fizz"` and `"Buzz"` are instances of __str__, so _str()_ is redundant.
2. You can return them directly e. g. `return "Buzz"`.
More
Hi, those list comprehensions are redundant, both `date1` and `date2` are iterables and you can unpack them directly:
return abs(d.date(*date1) - d.date(*date2)).days
When you need to import just one thing from a module you could simply write:
from datetime import date
...
More