40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
You can omit the _list_ here:
any(list(map(lambda x: x.isdigit(), data)))
as _map_ returns an iterable which _any_ can consume.
This pattern:
any(list(map(lambda x: x..., data)))
is there three times. You can replace it with _all_ and list comprehension/generator expression.
More
Lines 10-12 == re-inventing the wheel (check str.isdigit, str.islower, str.isupper)
More
Why not?:
def exclusive(x, y): return not(x == y)
def equivalence: return x == y
def implication: y if x else 1
More
Hi, this is two times the same code as you perform the same set of operation on _first_ and _second_.
A few suggestions:
1. You can use sorted(x) instead of x = list(x); x.sort():
x = sorted(x.lower())
2. You can avoid the redundancy mentioned above with a separate (or even nested) _
More
A _for_ loop would be a better solution for lines 5-10 e. g.:
for rep in (('IIII', 'IV'), ('VIV', 'IX')...):
large = large.replace(*rep)
__*__ before _rep_ unpacks the tuple.
More
Hi, I have two things:
1. Use str.join instead of resString + for loop (in this case ",".join())
2. list() is redundant on line 3 sorted() can consume sets.
More
Hi, two things:
1. list() is redundant as sorted can consume str.
2. lines 2 and 3 contains the same pattern, you could make it function or lambda function.
More
You can write:
if all(i.isalpha() for i in words[w:w+3]):
instead of:
if words[w].isalpha() and words[w+1].isalpha() and words[w+2].isalpha():
More
Hi, there are some things you can omit:
1. str.split returns a list so:
lst = words.split()
2. I don't see the point of this:
if type(lst[0]) == str: count = 1
# In fact you can omit the whole if and modify the for in a way described in no 3.
3. a) You can/should ite
More
Hi, this:
return count >= 3
# or this
return not count < 3
is the same as:
if count < 3:
return False
else:
return True
More
Hi, you can write line 2-4 on one line, because:
1. time.split(":") returns a list which is iterable
2. lines 3 and 4 contains the same pattern i. e. apply the same function on the list items, which is what __map__ does.
specs = map(int, time.split(":"))
# you can also write list com
More
Hi, it's written in little bit "schizophrenic style" I mean the for cycle with an if at the and.
Why not?:
return not any(i + j for i, j in zip(vector, vectorT))
More
Hi, flag variable, the break and the !=0 are redundant:
if matrix[i][j] + matrix[j][i]:
return False
More
I like this check:
if matrix[x][y]+matrix[y][x]!=0:
but this I would like even more:
if matrix[x][y]+matrix[y][x]:
More
Hi, you don't need those ugly backslashes. In parentheses you can have line breaks.
More
Hi, you can nest _generator expression_ and use _any()_:
return any(any(cw.endswith(word) for cw in words_set if len(cw)>len(word)) for word in words_set)
More