40
Last seen 1 day ago
Member for 9 years, 11 months, 4 days
Difficulty Advanced
Hi, one small thing: The parentheses around ",".join(phrases) are superfluous as you can chain methods in python.
More
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
I like your style. Your solutions are concise and clear. (I don't have to "be a parser" to read them :))
More
Hi,
1. != None is unnecessary.
2. There's three times the same pattern. Consider using _all_ and _list comprehension_ or _generator expression_ instead.
More
Hi,
1. Line 2: _if else_ is unnecessary, and in python you could write it like this:
return (0 <= row < height) and (0 <= col < width) and grid[row][col]
2. Line 10: a) _if ... else_ is unnecessary b) _x != 0 or y != 0_ is the same as _x or y_. So you could write this:
sum +=
More
Hi, two things:
1. __list__ is redundant as numbers_array is iterable.
2. in this case you can replace lambda x: abs(x) with abs
More
Hi _chr.isupper()_ returns a boolean value so == True is redundant.
More
See my comment on your Second solution.
Btw. I like this more than that one. Checking if index is valid by throwing exception (as you have it there) is not a good approach.
More
Hi, import _math.pow_ is redundant. There is a built-in operator for power: __**__.
More
Hi, look at slicing and indexing and in Python:
1. array[len(array)-1] == array[-1]
2. array[::2] does the same as your lines 9-11
Last thing: sum is not a good variable name as there's a built-in function called __sum__.
More
Hi even it's marked as Creative: To my mind __is not__ is not (:)) the correct comparison here. It should be !=.
More
Hi, powernumber is redundant, you could write:
return array[n] ** n
More
Hi, 3 little things:
# connection = (connection, ) is redundant
self.connections += (connection, )
# lambda in line 23 is redundant:
return reduce(set.union, self.connections)
# change self.connection to list as self.connection is mutable e. g.:
self.connections
More
Hi, you could omit the if in lambda:
# 1. using filter()
# 2. or use True == 0 and 0 * string = "":
x * x.isupper()
More
Hi, in this case:
lambda l: l.isupper()
# is the same as:
unicode.isupper # without ()!
More
Hi, two things:
1. Why text[::], why not just text?
2. lambda is redundant:
lambda x: x.isupper()
# is the same as
str.isupper # without ()!
More
Hi, a few things:
1. string is iterable therefore list() is redundant.
2. check str.isupper
3. in python you can write: 'A' <= letter <= 'Z'
More