40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
... two thumbs, but those [] on line 59 are redundant :)
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, 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 [] are redundant. You can write:
return sum(c in txt.lower() for c in words)
More
Hi, `list1` and `str1` are redundant:
return ''.join(re.findall('[A-Z]*', text))
More
Hi,
1. `&` means [_set intersection_](https://docs.python.org/3.4/library/stdtypes.html#set.intersection) in Python. Use `and` instead.
2. You could move line 10 inside the for loop and return the condition:
return number and lower and upper
More
Hi `x` is redundant:
return "".join(findall('[A-Z]', text))
P. S.: You can solve it without using __re__.
More
Hi, this is the same:
return firstWLcCounterList == secondWLcCounterList
is the same as:
if firstWLcCounterList == secondWLcCounterList:
return True
else:
return False
More
Hi,
1. `number/x == int(number/x)` ... ugh. Use `%` instead. Have a look at [this](https://docs.python.org/3.4/library/stdtypes.html#numeric-types-int-float-complex).
2. Line 16: `if not len(outputString):`
3. Have a look at other solution, this one is quite "overengineered"
More
Hi, have a look at _sum()_ and _extended slices_.
for w in range(0,len(array),2):
total += array[w]
# is the same as:
sum(array[::2])
More
Hi, `in` in Python is quite powerful:
if searchTerm in text: wordsFound += 1
# or even:
wordsFound += searchTerm in text
# or even shorter:
return sum(searchTerm in text for searchTerm in words)
More
Hi, `enumerate` is redundant:
for c in text:
...
You could use _filter()_ instead.
More
Hi, few things:
ad Line 2:
a = sorted(((x, abs(x)) for x in numbers_array), reverse=True)
But you actually don't need `a` and logic on line :
return sorted(numbers_array, key=abs)
More
Hi,
1. _bin()_ returns a __str__ therefore line 3 is redundant.
2. `b` is redundant. You can chain methods in Python.
return bin(number).count('1')
More
Hi,
1. there's a shorthand syntax for `R = R + 1` -> `R += 1`.
2. You could use _generator expression_ and _sum()_.
text = text.lower()
return sum(word in text for word in words)
More
Hi,
1. _str.isupper()_ return __bool__, therefore ` == True` on line 4 is redundant.
2. `text` is __str__, which is iterable:
for word in text: # This is
if word.isupper(): # a filter :)
S += w
return S
3. You could use _filter()_ and _str.join()_:
r
More