40
Last seen 1 day ago
Member for 9 years, 11 months, 3 days
Difficulty Advanced
Hi,
1. `result` is redundant. You can return the `sorted(...)` directly.
2. `lambda` is redundant. `key=abs` is enough.
Best,
suic
More
Hi,
1. `round(float())`s are redundant.
2. You can handle the `len(args) == 0` case with `try..except` but there are more elegant ways.
More
Hi, this is an anti-pattern:
if len(leftbrackets) == 0:
return True
else:
return False
# as len(leftbrackets) == 0 is allready a bool
return len(leftbrackets) == 0 # is enough
# You can even write:
return not leftbrackets
More
Hi,
1. You could write:
matchstring = ",".join(matchlist)
# instead of:
matchesstring = ""
for match in matcheslist:
matchesstring = matchesstring + match + ","
matchesstring = matchesstring[:len(matchesstring)-1]
2. Look at __set__ built-in type and set operations:
More
Hi,
1. this is quite inefficient as __str__ is immutable.
2. Look at negative indices. For non-empty string/list/tuple... `seq[:len(seq)-1] = seq[-1]`.
3. Look at _str.join()_.
More
Hi,
1. You use `stringnumber` only once, so you don't need it.
2. You could write `multtotal *= digit`.
3. `if digit:` is enough.
More
Hi,
1. look at the _sum()_ builtin:
sum(int(digit) for digit in xnorm)
2. In fact, you just need to count the number of "1" in xnorm, therefore:
return bin(n^m).count('1')
More
Hi, few comments:
1. _addup()_ is redundant.
2. You can write:
if condition:
return x
else:
return y
# like this:
return x if condition else y
[Here](http://www.checkio.org/mission/restricted-sum/publications/suic/python-3/sabinas-shortened/)'s a shortened versi
More
Hi,
1. _issufix()_ is redundant see [_str.endswith()_](https://docs.python.org/3.5/library/stdtypes.html?highlight=str.endswith#str.endswith)
2. `is not` and `!=` don't do the same thing (look at [this](https://docs.python.org/3.5/library/stdtypes.html#comparisons))
3. Instead of:
if word1 is
More
Hi, I have a few comments:
1. That `if..else` and the `password` variable are redundant. Btw. line 3 doesn't make much sense.
2. Expression in parentheses can contain line breaks. It looks better than `\`. (see below)
3. Finally: You don't need `re`. Look at [string methods](https://docs.python.or
More
Hi,
1. You could write `array[::2]`
2. and also use _sum()_ instead of for loop:
return array[-1] * sum(array[::2]) # That's it :)
More
Hi, let me deduce from your code first:
1. You're comming from the C-world.
2. You speak French.
I have a few pieces of advices:
1. Forget about semicolons in Python :)
2. Look at [_String Methods_](https://docs.python.org/3.5/library/stdtypes.html?highlight=str#string-methods).
More
Hi, good one. It's much more pythonic than your previous solutions. Two comments:
1. You should change the title a bit: "I love comprehensions!!!" :) Generators and comprehensions don't behave in the same way. (check this [blog post](http://python-history.blogspot.co.uk/2010/06/from-list-comprehens
More
Hi,
1. What is creative in this? Checking if a character is uppercase using `ord(symbol) > 64 and ord(symbol) < 91` is quite obvious.
2. You could use _str.isupper()_ for this.
3. Concatenation strings in Python using `+=` is an anti-pattern.
More