40
Last seen 1 day ago
Member for 9 years, 11 months, 4 days
Difficulty Advanced
Hi, this
try:
int(xy)
except ValueError:
...
is quite ugly and in fact you don't have to do that as there is the _str.isalpha()_ method:
if string.isalpha():
word_seq += 1
else:
word_seq = 0
More
Hi, you don't need re.sub. __str__ has _str.replace()_ method. You can also omit the new_string variable:
return ','.join(phrases).replace('right', 'left')
More
Hi, you don't need the message variable and you can omit []. You can also use str.uppercase instead of importing string.ascii_uppercase:
return ''.join(char for char in text if char.isupper())
# or you can use filter:
return ''.join(filter(str.isupper, text))
More
Hi, why not:
filter(None, iterable)
# instead of:
filter(bool, iterable)
?
More
Hi, let me have some comments:
You don't need:
1. the else branches at all.
2. "== True" as test is a bool.
3. the test variable as you can use any as a condition.
4. letts as you can use data instead.
5. the parentheses on lines 5-7.
After this basic cleanup your code looks like this:
def c
More
Hi, this is "overparenthesized" :D
# E. g.:
bin_n = bin(n)[2::][::-1]
bin_m = bin(m)[2::][::-1] + diff_len * "0"
More
Hi, look at documentation for _sorted()_. Sorted has _key_ argument, which is quite useful.
More
Hi, lambda here is completely unnecessary (or it has obfuscation purposes?).
return [x for x in data if data.count(x)>1]
More
Hi, you can replace the chain of ors with any():
checkio = lambda p: len(p) > 9 and not any((p.isalpha(), p.isupper(), p.islower(), p.isdigit()))
# or:
checkio = lambda p: len(p) > 9 and not any(f(p) for f in (str.isalpha, str.isupper, str.islower, str.isdigit))
More
Hi,
1. [] are redundant.
2. ... if ... else ... is also redundant:
return sum(w in text.lower() for w in words)
More
Hi,
# instead of
[int(i) for i in str(number)]
# you can write:
map(int, str(number))
More
Hi, you have three times the same pattern chained with and => you can use all() and generator expression instead.
More
Hi, have a look at [this](https://docs.python.org/3.4/library/stdtypes.html#truth-value-testing).
# You can omit the ... if ... else ...:
return bool(re.search('\D+( \D+){2,}', words))
Last but not least with \_\_import\_\_() and lambda you could transform it to a nice one-liner :)
More