40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, why not:
return ' '.join(w for m, w in MODULI if not number % m) or str(number)
# or even:
' '.join(w for m, w in ((3, 'Fizz'), (5, 'Buzz')) if not number % m) or str(number)
More
Hi, this is more "hard to read" than creative. I'm not a PEP8 dogmatist, but this looks better:
def checkio(n):
if n % 5 == 0 and n % 3 == 0:
return "Fizz Buzz"
if n % 3 == 0:
return "Fizz"
if n % 5 == 0:
return "Buzz"
return s
More
Hi, [] and `...if...else` are redundant. E. g.:
return ''.join(w for w in text if w.isupper())
# or even:
return ''.join(filter(str.isupper, text))
More
Hi,
1. In `checkio` you can use list comprehension:
def checkio(data):
return [x for x in data if nrre(data,x) > 1]
# nrre is like str.count so
def checkio(data):
return [x for x in data if data.count(x) > 1]
More
Hi, _bin()_ returns __str__ and it has a _str.count()_ method, so you don't need that for loop:
return bin(number).count('1')
More
Hi, `value` is redundant. With a list comprehension and _len()_, or with _sum()_ it could be shorter and nicer.
More
Hi,
1. __str__ is immutable so it's not the best type in this case.
2. _filter()_ or generator expression + "".join() would be better, e. g.:
return filter(str.isupper, text)
More
Hi, don't reinvent the wheel. Look at _str.join()_:
return "".join(phrases).replace("right", "left")
More
Man... are you serious? But with a funny name it could be `Creative` solution? Anyway that last if is redundant:
return count == 26
# shorter:
import string
return all(x in text for x in string.ascii_lowercase)
More
Hi,
1. you can write:
if x not in text.lower():
return False
return True
2. Instead of `abc=...` you can `import string` and use `string.ascii_lowercase`.
More
Hi, [] and ...if...else are redundant. You can write:
return sum(w in text.lower() for w in words)
More
Hi, once result is True, you don't need to continue. In fact you don't need `result` at all:
if eu >= 3:
return True
return False
More
Hi,
1.that last `if` and all the `== True` checks are redundant e. g.:
return all((a, b, c, d))
2. `data.split()` does nothing.
3. All `range (0, len(data) - 1)` are redundant:
for x in data:
...
etc.
More
Hi, that `else` is redundant:
if length == 0:
return 0
for e ... :
...
return ...
This way of doing it is too tedious
Tips:
Look at:
# 1. extended slices.
array[::2] # even elements
# 2. negative indices:
array[-1] # last element for non
More
Hi,
1. the last `if... else` is redundant:
return "111" in wordArray
2. Consider that fact that __str__ is immutable.
3. Once `"111" in wordArray` you don't need to continue:
for phraze in wordList:
...
if "111" in wordArray:
return True
return False
More