40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi,
1. `"".join(text)` is useless, it does nothing.
for i in text: # is enough
...
2. Look at _filter()_.
More
Hi,
1. Look at [_list comprehensions_](https://docs.python.org/3.5/howto/functional.html?highlight=list%20comprehension#generator-expressions-and-list-comprehensions).
2. Check [_functools.reduce()_](https://docs.python.org/3.5/library/functools.html?highlight=functools.reduce#functools.reduce).
More
Hi, I have two comments:
1. Don's use _tuple_ as variable name as [tuple is a built-in type](https://docs.python.org/3/library/stdtypes.html?highlight=tuple#tuple).
2. In fact you don't this variable at all as you can chain methods in python like this:
return ','.join(phrases).replace("ri
More
Hi, on lines 4 - 6 you have three times the same pattern. You could reduce the redundancy by using list comprehension:
hasDigit, hasUpper, hasLower = (bool(re.search(rgx)) for rgx in ('\d', '[A-Z]', '[a-z]'))
# in fact the has... variables are redundant as you could use all() instead o
More
Hi, with operator.mul it's more universal, but you can write it also this way:
return reduce(int.__mul__, filter(None, map(int, str(number))))
More
Hi, nice solution. You can shorten it:
new_list = sorted(list(args))
return new_list[-1] - new_list[0] if new_list else 0
More
Hi, good solution. It's more readable then mine :)
I have a some suggestions:
1. minX and minY are redundant as range() is zero based based by default:
range(minX, maxX) == range(maxX)
2. In lines 15-18:
# 1) You don't need nested if's as there's only one condition so you can
More
Hi,
1. What is creative in this? Checking if a character is uppercase using `ord(symbol) > 64 and ord(symbol) < 91` is quite obvious.
2. You could use _str.isupper()_ for this.
3. Concatenation strings in Python using `+=` is an anti-pattern.
More
Hi,
1. `type` is a keyword in Python.
2. If you need queue in Python use [deque](https://docs.python.org/3/library/collections.html?highlight=deque#collections.deque)
3. `neighbors` should be split to multiple functions instead of using `type` argument.
Regards,
suic
More
Hi, in fact you don't need to import string here. Look at str.isdigit, str.islower and str.isupper methods.
More
Hi, a "nice misuse" of `collections.Iterable`. There shorter and simpler way to write the same:
```python
def flat_list(items):
for x in items:
if isinstance(x, list):
yield from flat_list(x)
else:
yield x
```
Regards,
suic
More
Hi, lines 2-4 are redundant, just remove them. _numbers_array_ is iterable by itself so you don't have to convert it to list.
The pattern in lines 2-4 you can usually replace with a list comprehension/generator expression (look at [this](https://docs.python.org/3/howto/functional.html#generator-exp
More
Hi, `letters` is redundant.
len({char for char in text.lower() if char in string.ascii_letters}) == 26
More
Hi, in python you don't need auxiliary variable to swap values of two variables. E. g. to swap the values of a and b it's enough to do this:
a, b = b, a
More
Hi,
1. Notice that you do many steps twice.
2. The last if is unnecessary:
return liste1 == liste2
More
It's shorter and more readable with a generator expression:
```python
return chain.from_iterable(range(l, u+1) for l, u in items)
```
Regards,
suic
More
This
10. if c == end:
11. found_begin = False
could be:
10. if c == end:
11. return tmp_string
More
Alternative for 28-29.: `self.stuff.extend(unit() for i in range(amount))`
More