40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, few comments:
1. `lower_case`, `upper_case` and `digit` are actually _boolean flags_. So you can write:
lower_case, upper_case, digit = False, False, False
2. Instead of decrementing the value of those three, you can just change their values to True:
if s.isdigit():
digi
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, a small stylistic thing. This would be the correct indentation here:
return ",".join(sorted([word for word in first.split(',')
if word in second.split(',')]))
as _if word..._ belongs to the list comprehension.
More
Hi, there's a worth-to-learn trick for doing this in Python: `zip(*data)` :) Btw. `new` is redundant.
More
Hi,
1. `x` is already an __int__ therefore _int()__ is redundant.
2. _abs()_ is a function and `key` takes a function. Therefore `lambda` is redundant:
key=abs # is enough :)
More
Hi, few comments:
1. Line 12 is never reached => redundant.
2. Line 13-15 are also redundant.
3. Your code is not very Python. Fortunately Python is not C.
~~~~
def checkio(array):
# You can do this in Python :):
# i = s = 0
s = 0
if not array:
return s
# cleane
More
Hi,
1. `word` is an __int__ so `return word` is enough.
2. You could use _generator expression_ and the _sum()_ built-in function for this.
More
Even more elegant solution:
return sum(word in text.lower() for word in words) # :)
More
Hi,
1. Line 9 is never reached => redundant.
2. `if` on line 12 is redundant.
More
Hi, look at _list comprehensions_ e. g.:
message = [x for x in text if x.isupper()]
# or the filter() built-in function
message = filter(str.isupper, text)
More
Hi,
1. This is rather "selfobfuscating" than clear.
2. Look at _extended slices_. Both `indexlist` and `valuelist` are redundant:
valuelist == array[::2]
3. `if not array:` better than `if len(array) == 0:`
More
Hi,
1. `a`, `b` and `result` are redundant: `return max(args) - min(args)` is enough.
2. Same with lenght: `if len(args) == 0:`
More
Hi, `bin(number)` is a __str__, which has _str.count()_ method:
return bin(number).count("1")
More
Hi, a little code review:
1. Lines 6-8 are redundant.
2. Parentheses on line 2 and 3 are redundant:
if n < len(array):
return array[n] ** n
# is enough
More
Hi, this is way to complicated and completely misses the beauty and simplicity of Python:
1. Line 2: `numbers_array` is a __tuple__ which is iterable => _list()_ is redundant.
2. Lines 3, 4: Look at _extended slices_.
3. Lines 6-8: You don't need `tmp` variable as you can swap `j` and `j+1` like th
More
Hi,
1. `[::2]` is enough.
2. `if Z else` is even more pythonic.
3. The next step: Get rid off `...if...else...`.
Regards,
suic
More
Hi,
1. There's the _abs()_ built-in function: `return abs(d.days)`
2. You can unpack variables with `*` e. g.:
d = date(*date1)
More