40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, do not redefine _sum()_:
# This is shorter, nicer and faster
f = sum(map(abs, groups))
# than:
sum = reduce(lambda x, y : abs(x) + abs(y), groups)
More
Hi,
1. look at _any()_:
def contain(s, need): return any(c in need for c in s)
2. look at _str.isupper()_, _str.islower()_, _str.isdigit()_.
More
Hi, you could write:
text = "".join(filter(str.islower, text.lower()))
More
Hi,
1. you certainly heard about _any()_.
2. As Veky already told you: You can omit [] and _sum()_ the __bool__`s`.
3. etc. ...
More
Hi, lot of redundancy there
1. that `if...else` is redundant:
return len(password) >= 10 and match and match1 and match2
2. Or lines 4-6 contains the same pattern.
More
Hi, nice :) Can you do it without `if` and `try...catch`.
More
Clean?
def checkio(array):
return sum(array[::2]) * array[-1] if array else 0
More
Hi, why not:
return bool(re.search(r'([a-zA-Z]+) ([a-zA-Z]+) ([a-zA-Z]+)', words))
More
Hi, that `regex` dictionary is redundant:
regex = re.compile("[A-Z]")
...
if regex.match(c):
out += c
In fact you don't need regex at all:
return "".join(filter(str.isupper, text))
More
Hi, it would be faster and more memory efficient with _sum()_:
count_words = lambda text, words: sum(w in text.lower() for w in words)
More
Hi, one comment: I would replace lines 13-15 with one line:
# You can apply map(int, ) directly on splitted_data
# and use it as argument of date
year, month, day = map(int, splited_data[0].split('-'))
# In fact you can eliminate these these three variables
call_data
More