40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
As functions are [first-class citizens](http://en.wikipedia.org/wiki/First-class_citizen) in Python, you can write line 19 like this:
"".join(f(data) for f in (getThousands, getHundreds, getTens, getUnits))
More
Man, this is scary. So much redundancy: there's the same pattern 13(!) times.
Other things:
1. All the _nix_, _ni_, etc. are redundant and _niv_, _nix_, _nxl_ and _ncd_ are not used at all. E. g.:
nv = num / 5; ans += 'V' * nv
# is the same as
ans += 'V' * (num / 5)
2. Semico
More
I like your approach. In fact you can replace lines 44-52 with two lines of code :)
dig = str(dig).zfill(4)
return "".join(c[dig[i]] for i, c in enumerate((thou, hund, tens, ones)))
More
Check the [_divmod_](https://docs.python.org/3/library/functions.html#divmod) built-in function.
data, rest = divmod(data, 10)
# instead of:
rest, data = data % 10, data // 10
More
Hi, I have to comments. First you don't have to import string you can use string methods instead (try to look at help(str) or [here](https://docs.python.org/3/library/stdtypes.html?highlight=str#string-methods).
There's quite a lot of redundancy in this code. Lines 5-7 contain the same pattern. It
More
It's subjective but in this case using list comprehension would be nicer and also shorter :)
More
Hi I like your solution except from two things:
1. For thousands you can use the same logic as for ones, hundreds and tens as
'M' * 0 == ''
# then:
romanNumeral = THOUSANDS[(data // 1000) % 10]
2. Lines 8-10 (or even 7-10 if you apply my point no 1) contain the same patt
More
You can negate the first condition here:
if y == row and x == col:
pass
else:
if grid[y][x]:
count += 1
and reduce it to this:
if not(y == row and x == col) and grid[y][x]:
count += 1
or even:
count
More
Hi, line 5, 6 are almost the same. It's a good candidate for `lambda` or list comprehension.
More
Hi,
1. `lados` is redundant. `args` is a tuple => is iterable, so _list()_ is redundant.
2. you should decompose `args` like this:
a, b, c = args
3. You don't need _math.sqrt()_, there is the [_pow()_](https://docs.python.org/3.4/library/functions.html#pow) built-in function, and the `**` ope
More
Hi,
1. Line 6: [] are redundant.
2. Look at _filter()_
cnd = collections.Counter(filter(str.isalpha, text.lower()))
3. Line 7 that `for x sorted(): break` is so ugly. What's wrong with?:
return sorted([t[0] for t in most_common if t[1] == cnt_max], key=operator.itemgetter(0))[0]
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,
1. look at [_extended slices_](https://docs.python.org/3.5/whatsnew/2.3.html?highlight=extended%20slices#extended-slices).
2. `if not array:` is enough.
More
0 < len(array) <= 10 and 0 <= n and all(0 <= x <= 100 for x in array)
are preconditions so you can omit line 3.
More
This is not very pythonic:
text.lower().find(i) != -1
use _in_ instead:
i in text.lower()
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