40
Last seen 1 day ago
Member for 9 years, 11 months, 4 days
Difficulty Advanced
Hi, float division in boolean algebra task, why?
1. Line 13: return x == y
2. Line 11: return x != y
3. Line 7: return x or y
4. Line 5: return x and y
Conclusion: You don't need to import math.
More
Hi, the print statements are useless. If you really want to comment your code, then _comment_ and don't write print statements like these.
More
Man, ...
else:
S = S
Why? You don't need that branch at all.
Few tips:
1. Negative indices:
array[len(array)-1] == array[-1]
2. You can write x += 1 instead of x = x + 1.
3. Look at _sum()_ function.
return sum([::2]) * array[-1]
More
Hi, what's the point of the for loop? You do the same thing len(args) times.
# this is enough:
def checkio(*args):
if not args: return 0
return max(args) - min(args)
More
Hi, ... good, evil... that's funny :) but line 10 isn't:
return ",".join(curse) # is enough
More
Hi, you can replace lines 5-10 with:
return ','.join(list_phrases).replace('right', 'left')
More
Hi, you do the same thing len(phrases) times, why?
def left_join(phrases):
output = ",".join(phrases)
output = output.replace('right', 'left')
return output
# is enough.
# And now get rid of output variable as you don't need it:
return ",".join(phrases).re
More
Hi, the for loop is re-inventing the wheel as there's _str.join()_ method. And it's a misuse of _re_, as there's _str.replace()_ method.
More
Hi, you can use _str.replace()_ method and replace lines 2-4 with this:
return ",".join(phrases).replace('right', 'left')
More
Hi,
1. You don't need [].
2. You don't need _for_ at all as you can replace all at one, when you first join and then you use _str.replace()_ method.
More
Hi, one comment:
You don't need to replace one by one. __str__ has _str.replace()_ method, so instead of lines 5-8 you can write this:
return ",".join(phrases).replace('right', 'left')
More
Hi, you can shorten it using _any()_:
return any(a.endswith(b) for a, b in permutations(words_set, 2))
More
Hi, why try...except? You can easily handle it by _if_ or _and_. E. g.:
if array:
...
else:
return 0
More
Hi, you don't neet !=0 and in fact you don't need len():
if args:
...
else:
...
# is enough
More
Hi, you can shorten your code by using all(). Instead of nested ifs you can write:
return all(any(map(f, data)) for f in (str.isdigit, str.isupper, str.islower))
More