40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, you can shorten the last line like this:
return all(f.findall(data) for f in (r1, r2, r3, r4))
or you can go even further:
# Lines 4-7 contains the same pattern rx = re.compile(regex)
# You can extract the pattern and make a list comprehension or generator expression
r1, r2,
More
Hi,
1. _is_ isn't the right way to check equality here, use `==` instead.
2. You don't need the first `if` branch:
if setItem1 != setItem2 and setItem1 in setItem2[-suffixLength:]:
return True
3. But as it's been already mentioned: _str.endswith()_ is a better option.
4. Check the [_a
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, why not:
return (game_result[0][0]==who and ...)
That `if...else` is redundant.
More
Hi, there's nothing wrong with this solution, but you can make it more concise:
1. bin(number) is a _str_ so you don't need str().
2. This:
count += (x == "1") # is the same as
if x == "1":
count += 1
At the end because bin(number) is _str_ you can omit the count variable,
More
Hi, at first sight I was a bit surprised that it works :) as __is__ isn't the right comparison in this case, there should be ==. I have a few comments:
1. The condition in the first if is a precondition for this task, so you could omit it. This condition you could write in a more Pythonic (math-lik
More
Man... why???
1. Forget about `else: pass`! Those lines do nothing.
2. Use `if` wisely:
answer = count >= 3
# is the same as:
if count >= 3:
answer = True
else:
answer = False
3. `answer = bool`? Why? Why not `answer = True`? Or why don't you return immediate
More
Hi, look at [_sum()_](https://docs.python.org/3.5/library/functions.html?highlight=sum#sum) built-in function.
More
Hi, __str__ is immutable in python, so it's not the best type for accumulation.
Tip: Look at _filter()_.
More
Hi, you can use _reduce()_ here:
return reduce(int.__mul__, map(int, num_txt))
More
Hi, `lambda` is redundant:
for e in map(unicode.isalpha, words.split())
More
Hi, you could use lambda and \_\_import\_\_() to make it one-line-one-liner :)
More
Hi, I have a few comments:
1. You can omit the if ... else.
return sum(map(lambda word: word in text, words))
2. I think list comprehension or generator expression would be better here.
return sum(word in text for word in words)
More
Hi, generator expression would be nicer. Or you can write:
return sum(map(text.lower().__contains__, words))
More
Hi, you missed a bit the concept of list comprehension:
You could write:
new = [i for i in data if data.count(i) != 1]
or even:
return [i for i in data if data.count(i) != 1]
More
Hi, that `lambda` is not necessary. You can use `*` for unpacking, e. g.:
days(*date1)
More
Hi,
1. Last if is redundant: `return x >= 3`
2. On line 7 you can immediately `return True`.
More