40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, look at [this](https://docs.python.org/3/library/stdtypes.html?highlight=str.isupper#truth-value-testing).
You can omit the majority of ifs:
1. Lines 5-6: return x and y
2. Lines 8-9: return x or y
3. Lines 14-15: return x != y
4. Lines 11-12: not(x and not y)
5. Lines 17-18: return x == y
More
Hi, I have a few comments:
1. You don't need _re_ as __str__ has _str.replace()_ method.
2. When you join first and then replace, you can replace all at once:
return ",".join(phrases).replace("right", "left")
More
Hi,
1. Don't comment obvious things. It's not useful.
2. All that "magic" with `Counter.most_common` is redundant.
Regards,
suic
```python
from collections import Counter
def checkio(lis):
c = Counter(lis)
return [e for e in lis if c[e] > 1]
```
More
Hi, __bool__ is a subtype of __int__, therefore the nested `if`s are redundant, e. g.:
elif operation == "equivalence":
return x == y
elif operation == "exclusive":
return x != y
More
It's not a bad solution, but it can be improved:
1. [Set](https://docs.python.org/3/library/stdtypes.html?highlight=intersection#set-types-set-frozenset) is more suitable for this task.
2. You could replace this:
c = []
for i in a:
for j in b:
if i==j: c.append(i
More
Hi,
1. `str.capitalize` makes sense if you apply it on string longer than one character. `str.upper` is enough here.
2. Instead of `if text[-1]!='.':` you can use `text.endswith('.')`
3. You can shorten the last three lines like this:
```python
return text + "." * (not text.endswith('.'))
```
R
More
Hi, you could write it also this way:
return bool(re.compile('.*?[a-zA-Z]+ [a-zA-Z]+ [a-zA-Z]+.*?').match(words)) # :)
More
Even more elegant solution:
return sum(word in text.lower() for word in words) # :)
More
Hi,
1. This is rather "selfobfuscating" than clear.
2. Look at _extended slices_. Both `indexlist` and `valuelist` are redundant:
valuelist == array[::2]
3. `if not array:` better than `if len(array) == 0:`
More
Hi, this is way to complicated and completely misses the beauty and simplicity of Python:
1. Line 2: `numbers_array` is a __tuple__ which is iterable => _list()_ is redundant.
2. Lines 3, 4: Look at _extended slices_.
3. Lines 6-8: You don't need `tmp` variable as you can swap `j` and `j+1` like th
More
Hi,
1. There's the _abs()_ built-in function: `return abs(d.days)`
2. You can unpack variables with `*` e. g.:
d = date(*date1)
More
Hi, look at _any()_ and _generator expressions_:
return any(i != j and (i.endswith(j) or j.endswith(i)) for i in words_set for j in words_set) # That's it :)
More
Hi, this is not Pythonic:
1. `phrases` is a __tuple__ which is iterable, therefore you can write:
for i in phrases:
ret += i.replace("right", left")
...
2. __str__ has _str.join()_ method, which does the same as your for loop:
ret = "".join(i.replace("right", "left") for
More