40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, `1` is the _neutral element of multiplication_ lines 8 and 9 are redundant (`total * 1 == total`). You could use the _reduce()_ built-in function for this.
More
Checking if string is digit by trowing ValueError... Why?
Have you heard about str.isdigit()? (check help(str.isdigit))
More
Hi, it's better to avoid complex lambdas in `reduce`.
Regards,
suic
```python
# instead of
if len(st) == 1: # - this is incorrect: checkio(9) == 9
return 1 # /
return reduce(lambda x, y: int(x) * int(y), b)
# you can write
return reduce(lambda x, y: int(x) * int(y), b, 1) # check http
More
This is so funny :)
1. "all the magic" (including `itertools.groupby`) on one-line.
2. wrapped by a typical newbie `if...else...` anti-pattern.
```python
return (
subj.isupper() # bool
or subj.endswith('!!!') # bool
or any(...) # bool
)
More
Hi, `listToString` is reinventing the wheel. Look at [_str.join_](https://docs.python.org/3.5/library/stdtypes.html?highlight=str.join#str.join).
More
Hi,
1. `myarr` is redundant.
2. _sorted()_ works with __set__.
3. There is the `&` operator for _set intersection_.
def checkio(fst, sec):
return ','.join(sorted(set(fst.split(',')) & set(sec.split(','))))
# or even:
checkio = lambda fst, sec: ','.join(sorted(set(fst.split('
More
Hi, look at [bitwise exclusive or operator](https://docs.python.org/3.5/library/stdtypes.html?highlight=str.count#bitwise-operations-on-integer-types) in Python (`^`).
More
Hi, lines 3-6 represent a common newbie anti-pattern:
# Step 1: the condition is a bool so if..else is redundant
x = search('([A-z]+ [A-z]+ [A-z]+)', words)
return x
# Step 2: x is redundant
return search('([A-z]+ [A-z]+ [A-z]+)', words)
More
Hi, look at
1. [__collections.Counter__](https://docs.python.org/3.5/library/collections.html?highlight=counter#collections.Counter).
2. the [_filter()_](https://docs.python.org/3.5/library/functions.html?highlight=filter#filter) built-in function.
3. the [_str.islower()_](https://docs.python.org/3
More
Hi, look at:
1. [_fractions.gcd()_](https://docs.python.org/3.5/library/fractions.html?highlight=fractions.gcd#fractions.gcd)
2. and [_functools.reduce()_](https://docs.python.org/3.5/library/functools.html?highlight=functools.reduce#functools.reduce).
More
Hi, lines 2, 4 and 5 are pointless. Look at the documentation to [*args](https://docs.python.org/3.4/tutorial/controlflow.html#arbitrary-argument-lists).
def checkio(*args):
try:
return max(args) - min(args)
except ValueError:
return 0
# That's it
More
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
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, 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