40
Last seen 2 days ago
Member for 9 years, 10 months, 7 days
Difficulty Advanced
Hi, I like you solution except from it's repetitive nature, which you can avoid:
base = "I"*data
rs = (("I"*5, "V"),
("V"*2, "X"),
("X"*5, "L"),
("L"*2, "C"),
("C"*5, "D"),
("D"*2, "M"),
("DCCCC", "CM"),
("CCCC", "CD"),
More
Hi, two comments:
1. You could "precompile" the regexes and used the compiled version in `re.search`.
2. Instead of `(c for c in word)` you could write `iter()`.
```python
import re
def is_stressful(subj):
matchers = [
re.compile('+[.!-]*'.join(iter(word)), re.I)
for word in
More
Hi, you could clean it up a bit. E. g.:
1. Remove the print statements
2. int(a, 10) == int(a) so you can omit the ", 10"
3. Try to look at [this](https://docs.python.org/2/library/stdtypes.html#truth-value-testing).
# Because [] == False == 0:
if stack != []: == if stack:
if sta
More
Hi, you can do it without _re_. [_filter()_](https://docs.python.org/3/library/functions.html?highlight=filter#filter) is perfect for this:
return "".join(filter(str.isupper, text))
More
Hi, one of the most important and powerful feature of Python is `in`:
for word in words:
now = 0;
word = word.lower();
wordLength = len(word);
while now < textLength - wordLength:
if text[now:wordLength+now] == word:
count+=1;
More
Hi, I have some comments:
1. __str__ is not a good name as [__str__](https://docs.python.org/2/library/functions.html#str) is a built-in python class
2. Instead of defining str variable and checking s in str you could use the islower() method the __str__ class. Check help(str.islower).
More
Hi, nice one. You can write it like this:
```python
verify_anagrams = lambda *a: list.__eq__(*map(f, a))
# or this
from operator import eq
...
verify_anagrams = lambda *a: eq(*map(f, a))
```
Regards,
suic
More
Hi, few things:
1. Commenting obvious things isn't a good practice.
2. `str` is iterable so there's no need to convert it to `list`.
3. `1` is the [identity element](https://en.wikipedia.org/wiki/Identity_element) of multiplication. (see below)
4. Look at `functools.reduce`.
Regards,
suic
```pyt
More
Hi,
1. You can have nested generator expressions/list comprehensions and there's the _all()_ built-in function.
2. You don't need to import re as you don't it.
3. data is __str__ which _is iterable_ so list() are redundant.
4. You don't the ifs in generator expressions:
def checkio(data):
More
Nice, but I would shorten _eq_ a bit:
eq = lambda w: sorted(filter(str.isalpha, w.lower()))
More
Hi, instead of:
if len(args) == 0:
...
you could write:
if not args:
...
More
Hi, let's have a look at your `get_bin` function:
```python
def get_bin(number):
return (list(map(int, list(str(bin(number))[2:]))))
```
1. `bin()` returns a __`str`__ => __`str`__ is redundant.
2. __`str`__ is iterable => `list` is redundant.
```python
def get_bin(number):
return list(map
More
Hi, why not?:
return sum(date(year, m+1, 13).weekday() == 4 for m in range(12))
More
Hi, instead of lines 2, 4-6 you can write this:
return sum(word in ltext for word in words)
More
Hi, a minor thing:
checkio = lambda s: any(y != x and y.endswith(x) for x,y in product(s, s))
# or one-linerish :)
checkio = lambda s: any(y != x and y.endswith(x) for x,y in __import__("itertools").product(s, s))
More