40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
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
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
Hi, when you first join and then replace, you can do all the replacements at once:
return ",".join(phrases).replace("right", "left")
More
You gave up to early. There's a way to make it a one-line with lambda and \_\_import\_\_ :)
More
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
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
_toString()_ looks a bit "javaish" :)
Just one thing. Why not:
tmp = [int(''.join(toString(f))) for f in list(factors)]
instead of:
tmp = []
for f in list(factors):
tmp.append(int(''.join(toString(f))))
?
More
So, you want to learn [list comprehensions](https://docs.python.org/3/howto/functional.html?highlight=comprehension#generator-expressions-and-list-comprehensions)? :) This mission is an ideal candidate for it.
More
Hi, try to look at help(str) or [this](https://docs.python.org/3/library/stdtypes.html?highlight=str#string-methods).
newphrase =""
for word in words:
newphrase = newphrase + "," + word
newphrase = newphrase.lstrip(",")
equals to:
newphrase = ",".join(words)
More
Hi, `median_...` variables are redundant, you could write e. g.:
return (data[len(data)/2] + data[len(data)/2-1]) / 2.0
More
Hi,
1. look at `list comprehensions`.
2. `counter` is redundant:
if data.count(element) > 1:
...
More
Hi, that `if` is redundant:
return nnn_str1 == nnn_str2
There's fair amount of duplication in your code:
def helper(s):
return sorted(s.lower().replace(" ", ""))
def checkio(str1, str2):
return helper(str1) == helper(str2)
More
Hi, you could write:
# empty array as treated as false:
if not array:
return 0
# total is redundant:
return sum(array[::2]) * array[-1]
More
Hi, that `== True` is redundant:
if sub in text.lower():
total += 1
Tip: Look at _sum()_ and _generator expressions_.
More