40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
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,
1. _list()_ is redundant as _sum()_ accepts _generator expressions_.
2. _int()_ is redundant as __bool__ is just a subclass of __int__.
return sum(word.lower() in text.lower() for word in words)
More
I like your style. Your solutions are concise and clear. (I don't have to "be a parser" to read them :))
More
Hi,
1. _str.isupper()_ returns a __bool__ therefore `== True` is redundant.
2. __str__ is immutable, therefore it's not a good type for accumulating values.
3. Look at [_filter()_](https://docs.python.org/3.5/library/functions.html?highlight=filter#filter) built-in function and the [_str.join()_](h
More
Hi, using indexes is useless here. Text is __str__ which is iterable, therefore you can write:
for i in text:
if i.issupper(): # Don't forget the parens :)
x += i
IMO list comprehension + "".join() would be more suitable here.
More
Hi, look at:
1. [_extended slices_](https://docs.python.org/3.5/whatsnew/2.3.html?highlight=extended%20slices#extended-slices) and
2. the [_sum()_](https://docs.python.org/3.5/library/functions.html?highlight=sum#sum) built-in function.
More
Hi, you can shorted this even more. _checkio()_ in fact equals to _sum()_ so:
checkio = sum # is enough :)
More
Hi, `return` is a statement _not_ a function. Parentheses on lines 11, 13, 15, 17 are redundant.
More
Hi,
1. You could write alphabet as a string: "abcdefghijklmnoprstuvwxyz" as __str__ is is iterable.
2. The if is redundant as:
if condition:
return True
else:
return False
# is the same as
return condition
More
Hi, I have a few comments:
1. Line 2-4 for are useless. On line 8 you use x.isalpha() which returns False for white spaces, so you don't need to remove them previously. All you need to preserve is this:
text = text.lower()
# and then replace no_white with text
for x in text:
More