40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi,
1. Lines 8-16 reminds me: ["Empty spaces - what are we living for..."](https://vimeo.com/19166601) :D
2. `n` and `y` are redundant and return value doesn't have to be parenthesized.
3. Line 4: `arr[0:len(arr):2] == arr[::2]` and for non-empty lists: `arr[len(arr)-1] == arr[-1]`.
return su
More
Hi, the built-in [__set__](https://docs.python.org/3.5/library/stdtypes.html?highlight=str.count#set-types-set-frozenset) object is better for this purpose than __list__. Look at [_set.intersection()_](https://docs.python.org/3.5/library/stdtypes.html?highlight=str.count#set.intersection).
More
Hi, when you have the following pattern:
if condition:
continue
else:
do_something
is better to rewrite it like this:
if not condition:
do_something
e. g.:
if len(result) != 0:
del result[0]
Then have a look at [this](https://docs.python.org/3.5/l
More
```python
# redundant
# +-------------------------------------+
# | |
# V V
return max([(data.count(x), x) for x in set(data)])[1]
# \---------------------------------------
More
Hi, lambda is redundant as `data.count` is a function, so `return max(data,key=data.count)` is enough. Regards, suic
More
Hi,
1. this `text.lower().find(l) == -1` is very un-pythonic. One of the most useful and powerful thing in Python is `in`:
return not any(l not in text.lower() for l in letters)
# or:
return all(l in text.lower() for l in letters)
2. You could use `string.ascii_lowercase` instead
More
Hi, `...if...else...` is redundant:
```python
# bool
# /-------------------\
return True if len(set(elements))<=1 else False
# \--------------------------------------/
# bool
return len(set(elements))<=1
```
Regards,
suic
More
Hi, you don't need the `result` variable as well as the `number` variable. Line 19 is redundant.
More
Hi, _bin()_ returns a __str__, which has _str.count()_ method:
return bin(number).count('1') # That's it :)
More
Hi, this is not Pythonic for several reasons:
1. Line 2: `words` is a __set__, which is _iterable_ => no need to convert to __list__.
2. Line 4: `words` is _iterable_ therefore:
def count_words(text, words):
x = 0
for word in words)):
if word in text.lower():
More
+5 for not using [fnmatch](https://github.com/python/cpython/blob/3.6/Lib/fnmatch.py)
More
Hi, I just would mention, that [] can be used instead of list() in this case:
[... for ... in ... if ...]
More
Hi, I have two comments:
1. You don't need to assign the value of enumerate (lines 2 and 6). You could write this:
for i, _ in enumerate(matrix):
...
for j, _ in enumerate(line):
2. But in fact using enumerate on lines 2 and 6 is inappropriate. This would be better:
fo
More
Hi, the same on one line:
```python
def first_word(text):
return text.replace('.', ' ').replace(',', ' ').strip().split()[0]
```
Regards,
suic
More
Hi, the use of `%` is nice but this solution is very inefficient as `str` is immutable and the following is an antipattern:
```python
# this creates len(sequence) str objects
s = ''
for element in sequence:
s += do_somthing_with(element) # creates a new str
# these two are equivalent and way
More
Hi that else branch is redundant.
if ...:
if lis is None and uis is None and dis is None and ais is None:
return True
# That return False is also redundant
return False
Look _any()_, _all()_ and _map()_.
More