40
Last seen 1 day ago
Member for 9 years, 11 months, 4 days
Difficulty Advanced
Hi, its a bit "agyonfunkcionalt" :):
1. All the lambdas are redundant as in a) Python functions are first class citizens and b) you can use the methods of built-in types directly.
2. In this case any_with_pred is also redundant.
def checkio(data):
predicates = [str.isdigit, str.islowe
More
Hi, this is a misuse of _(x)range_. Look at extended slices:
array[::2] # even elements
More
Hi, don't use _sum_ as a variable name. It's a built-in function. Look at documentation for [_int_](https://docs.python.org/3.4/library/functions.html#int).
More
Hi, lambda is redundant. _key_ expects a function and _abs()_ is a function, so:
return sorted(number_array, key=abs) # is enough
More
Hi [] are redundant. You can write:
return sum(c in txt.lower() for c in words)
More
Hi, on line 8, 9 the right-hand sides differs in one number. E. g.:
even, odd = ({c for i,c in enumerate(word.upper()) if i%2==x} for x in (0, 1))
More
Hi, list(filter(...)) and that _dictionary comprehension_ on line 10 are a bit overkill. It can be done with a one-line long _list comprehension_.
More
Hi,
1. Comments makes it hard to read.
2. What's the reason for this assignment: ref_list = string.ascii_lowercase? ascii_lowercase is just a string.
3. __set__ has _set.add()_ method so you don't need to use |=.
4. The last if is redundant:
return len(new_set) == len(ref_list)
P. S.: Yo
More
Hi,
1. _bin()_ return a __str__, so str() is redundant.
2. __str__ has count method, so the for loop is redundant.
More
Hi, the last if and all the == True tests are redundant:
return a and b and c and len(data) > 9
def checkio(data):
# If the string is not long enough you don't need the whole for loop
if len(data) < 10: return False
# a, b and c are bool values
More
Hi, you can use * for unpacking _date1_ and _date2_:
return abs(date(*date1) - date(*date2)).days
More
Hi, nice one :) Can you make it a one-liner? :) First step is to remove the redundant _result_ variable.
More
Hi, straightforward... hmmm... but not pythonic:
Look at extended slices and _sum()_ built-in function:
array[::2] # even elements
sum(array[::2]) # sum of even elements
More