40
suic
16 39 57
9964/ 10664
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Best reviews / Newest reviews
functools & operator-otonvm
Hi, you could use _int.\_\_mul\_\_()_. More
First-StereoCat
Hi, `fabs` is redundant `abs` is enough. More
First-StereoCat 1
Hi, 1. `first` and `second` are strings so _str()_ is redundant. 2. Look at _list comprehensions_ and _generator expressions_ or _filter()_: result = [word for word in b if word in a] result = filter(a.__contains__, b) # or even: return "".join(sorted(filter(a.__contains__, More
First-StereoCat
Hi, 1. `sequence` is iterable, so line 6 is redundant. 2. Look at _enumerate()_. 3. `range(0, len(a)) == range(len(a))` count = 0 for i, x in enumerate(sequence): for y in sequence[i:]: if x > y: count += 1 return count # or with sum() and More
First-StereoCat
Hi, look at _sum()_ and generator expression: return sum(i in text for i in words) More
First-StereoCat
Hi, 1. Look at _filter()_. result = filter(str.istitle, text) 2. `is` stands for _idendity_ __not__ _value_ comparison. Don't use it for these cases, use `==` instead. 3. That `is True` or `== True` is redundant as _str.istitle()_ returns __bool__. More
First-StereoCat
Hi, all those nested `if`s are redundant. Look at documentation to [__bool__](https://docs.python.org/3.4/library/functions.html#bool) it's a subclass of __int__ (True == 1, False == 0). Therefore you can write e. g.: elif "exclusive" in operation: return x != y elif "equivalence" More
First-StereoCat
Hi, `text` is redundant. You can chain methods in Python: return ",".join(phrases).replace('right', 'left') More
chr()-otonvm
Hi, you could use 1. _dictionary comprehension_ for `row_indexes`: row_indexes = {v: k for k, v in dict(enumerate(map(chr, range(97, 105)))).items()} 2. _list comprehension_ for `pawn_indexes`: pawns_indexes = [(row_indexes.get(pawn[0]), int(pawn[1]) - 1) for pawn in pawns] 3. _sum()_ w More
endswith-otonvm
Hi, `is` and `is not` are for _identity comparison_ use `==` and `!=` instead. More
set/sort/join-otonvm
Hi, 1. Line 9 is redundant. 2. You could use _sorted()_ instead of _list.sort()_: first = set(first.split(',')) second = set(second.split(',')) union = first & second return ",".join(sorted(union)) # or even: return ",".join(sorted(first & second)) More
First-AlexanderKrivenko 1
Hi, 1. You don't use `string` so that import is useless. 2. The last if redundant: return (len(data)>=10) and (pD is not None) and (pCha is not None) and (pChA is not None) 3. All the `is not None` statements are redundant. 4. You can use _all()_ instead of chained `and`s: return all((l More
any(filter())-otonvm
Hi, it's kinda repetitive. Look at _all()_ and _generator expressions_. More
Regexp approach-rugala
Hi, cool! :) But: 1. That _bool()_ is redundant (look at [this](https://docs.python.org/3.4/library/stdtypes.html#truth-value-testing)). 2. Look at _all()_: return all(re.compile(r).search(data) for r in [r'\d', r'[a-z]', r'[A-Z]']) # or even: return len(data) >= 10 and all(re. More
not in lower()-otonvm
Hi, look at _all()_ and _any()_. More
sorted abs-otonvm
Hi, __tuple__ is iterable, therefor _list()_ is redundant. More
One-liner-otonvm
Hi, when you first join and then replace, you can do all the replacements at once: return ",".join(phrases).replace("right", "left") More
:D I really wanted one-liner-Lasica
You gave up to early. There's a way to make it a one-line with lambda and \_\_import\_\_ :) More
Straightforward-CryteLynn
Hi, let me have some comments: char.islower() is the same as: char.lower() == char char.isupper() is the same as: char.upper() == char use these two and you can omit the: for char in data: if char.isalpha: ... char.isdigit() is the More
ifLoop-donBit 1
In my opinion this is for two thumbs downs (You're lucky I can't do it as thumbs can't be negative :)) Here my explanation of thumbs downs: This is redundant: common = [] for word in set1: if word in set2: common.append(word) Set intersection is the right way in t More