40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
This will evaluate everything before it's checked with `any()`. It can be avoided by chaining `or`s.
More
Shorter alternative:
```python
def checkio(data, s=0):
return data and checkio(data, s + data.pop()) or s
```
More
`from import *` is not a good practice in general and there's no good reason reason to use this as you use only a class a function from that module. Regards, suic
More
Alternative:
```python
def convert(n, d, f=__import__('itertools').product, r=range(1, 100), s=__import__('re').sub, q= __import__('decimal')):
q.getcontext().prec = 100
k, p = str(q.Decimal(n)/d).replace('.', ''), str(n/d).find('.')
for a, b in [(k[:x], k[x:][:y]) for x, y in f(r, r) if
More
Alternatives:
32.-33. self.units.extend(ones_class() for _ in range(number))
35.-39. def is_someone_alive(self):
return any(one.is_alive for one in self.units)
More
Hi, `if all(digit in possible for digit in number):` is a shorter alternative for line 5. Regards, suic
More
Hi, here's a bit shorter alternative:
```python
import string
def checkio(str_number, radix):
d = dict(zip(string.digits + string.ascii_uppercase, range(36)))
decimals = [d[num] for num in str_number]
if radix <= max(decimals):
return -1
return sum(dec * radix ** (l
More
Hi, I finally found a solution which doesn't use exceptions. However, this is quite inefficient:
1. `str_number = str_number[1:]` creates unnecessary intermediate strings. `for` loop is the preferred way to iterate over an iterable including `str`.
2. No 1. is actually needed because of `len(str_nu
More
Alternative for 28-29.: `self.stuff.extend(unit() for i in range(amount))`
More
You can avoid the conversion to list on line 6 with
```python
power_plants = {next(iter(n-{i})): power_plants[i]-1 for n in network
```
Regards,
suic
More
Very nice! IMO lines 7-9 would be more readable this way:
```python
s |= {
n1 if c==n2 else n2
for c in s
for n1, n2 in network
if c==n1
and n2 not in s or c==n2
and n1 not in s
}
```
More
This is an anti-pattern:
```python
string = ''
for i in self.connected:
string += i.name + ' '
string = string[:-1]
```
You could write this instead:
```python
string = " ".join(i.name for i in self.connected)
```
This is alternative for 85-89:
```python
return {node.name for node in nodes
More
This
10. if c == end:
11. found_begin = False
could be:
10. if c == end:
11. return tmp_string
More
It's shorter and more readable with a generator expression:
```python
return chain.from_iterable(range(l, u+1) for l, u in items)
```
Regards,
suic
More
As you actually don't use `item` except for decomposing it, you can do the decomposition directly in the for loop:
```python
for first, last in items:
# ...
```
Regards,
suic
More
A bit shorter and more efficient:
```python
for a,b in sorted(items):
mas += range(a,b+1)
```
More
That list comprehension on line 6 is redundant:
```python
# you can use `list()` instead of list comprehension
output.extend(list(range(i[0], i[1]+1)))
# but you don't need it as `list.extend` takes iterables so you can use range directly
output.extend(range(i[0], i[1]+1))
# and there's a shortha
More
Compared to other creative solutions, this one has at least a `lambda` :)
More
In Python `super().__init__()` is enough. Also, you could make `is_alive` a
property which prevents accidental assignments. Regards, suic
More
So, ASM means Absolute Sado-Maso? Btw. what is the purpose of (can't you just omit it)?
```python
pass # BCS BITCNT
```
Regards,
suic
More