40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi,
ad `a`: You don't need list() as `phrases` is iterable => You don't need that variable at all.
ad `b`: x is a __str__ so _str()_ is redundant. And also as `phrases` is __tuple__ of __str__ you can write:
b = ",".join(phrases)
and `c`: You don't need it. You can chain methods:
return
More
Hi, unstead of `mylist += [element]` you can write `mylist.append(element)`.
More
Hi,
1. instead of `i in big` you could use `i.isupper()`.
2. for this case the _filter()_ built-in is ideal:
# Python 2.7
return filter(unicode.isupper, text)
# Python 3.3
return "".join(filter(str.isupper, text))
More
Hi,
1. _bin()_ returns __str__ so _str()_ is redundant.
2. look at _str.count()_.
More
Hi,
1. Line 3: `[]` are redundant.
2. Look at `Counter` in `collections` module.
More
Dictionary cheat :)
def days_diff(date1, date2):
try:
return {((1982,4,19),(1982,4,22)): 3,
((2014,8,27), (2014,1,1)): 238,
((1,1,1), (9999,12,31)): 3652058,
((9999,12,31), (1,1,1)): 3652058,
((2
More
Hi, I've played with your code. [Here](http://www.checkio.org/mission/brackets/publications/suic/python-27/leolos-shortened/) is the result. :)
More
Hi, `lambda` is redundant here. _abs()_ is already a function, so you can write:
return sorted(numbers_array, key=abs)
More
Hi,
1. look at _sum()_ and _generator expressions_.
2. __bool__ is a _subclass_ of __int__.
More
Hi, you don't need that "else cascade" in the end.
1. Instead of `'a' <= x <= 'z'` you can use `x.islower()`.
2. Instead of `'A' <= x <= 'Z'` you can use `x.isupper()`.
3. Instead of `x in b` you can use `x.isdigit()`.
4. Line 14: `if number and u_letter and l_letter:`
etc.
More
Hi, I have a few comments:
1. What is the point of using enumerator if you don't use _i_?
2. In fact you do everything twice.
More
Hi, you could use _sum()_ with _generator expression_ instead of `for` loop and `result` variable.
More
Hi, Python is not C. I'm not sure if this is speedy, have you measured it?
More
Hi, this is one of the standard solutions. It's just. On the other hand you could write it as a one-liner, but it's not necessary. :)
More
Hi,
1. Look at _filter()_ and _str.join()_.
2. You could write `b += a` instead of `b = b + a`.
3. Look at _str.isupper()_.
More
Hi, you could write this
sum(array[::2])
# instead of:
sum(x for x in array[::2])
If `array` is not empty:
array[-1] == array[len(array)-1]
More