40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, you can use `str.__contains__`:
return len(filter(text.lower().__contains__, words))
# or sum()
return sum(w in text.lower() for w in words)
More
Hi, that `lambda` is redundant:
return reduce(int.__mul__, map(int, str(number).replace("0", "1")))
More
Hi, look at _list comprehensions_ e. g.:
message = [x for x in text if x.isupper()]
# or the filter() built-in function
message = filter(str.isupper, text)
More
Hi, this is "overparenthesized" :D
# E. g.:
bin_n = bin(n)[2::][::-1]
bin_m = bin(m)[2::][::-1] + diff_len * "0"
More
Hi,
1. there's also 'str.isalnum()`.
2. I would move the len(data) < 10 to the beginning, once data is to short, you don't need to make the rest of the checks.
3. `bool` is redundant and it's not a good variable name as it's a name for a built-in type.
More
Hi, that if is redundant:
return sorted(first_word.lower()) != sorted(second_word.lower())
More
Hi, [] is redundant. _filter()_ built-in would be better here:
return ''.join(filter(str.isupper, text))
More
Hi, look at documentation for _sorted()_. Sorted has _key_ argument, which is quite useful.
More
Hi,
1. `a`, `b` and `result` are redundant: `return max(args) - min(args)` is enough.
2. Same with lenght: `if len(args) == 0:`
More
Hi, you can shorten your code like this:
def checkio(data):
data.sort()
length = len(data)
if length%2 == 0:
return (data[int((length/2)-1)] + data[int(length/2)])/2
else:
return data[int((length-1)/2)]
More
Hi, `1` is the _neutral element of multiplication_ lines 8 and 9 are redundant (`total * 1 == total`). You could use the _reduce()_ built-in function for this.
More
Checking if string is digit by trowing ValueError... Why?
Have you heard about str.isdigit()? (check help(str.isdigit))
More
Hi,
1. `myarr` is redundant.
2. _sorted()_ works with __set__.
3. There is the `&` operator for _set intersection_.
def checkio(fst, sec):
return ','.join(sorted(set(fst.split(',')) & set(sec.split(','))))
# or even:
checkio = lambda fst, sec: ','.join(sorted(set(fst.split('
More
Hi, look at [bitwise exclusive or operator](https://docs.python.org/3.5/library/stdtypes.html?highlight=str.count#bitwise-operations-on-integer-types) in Python (`^`).
More
Hi, `listToString` is reinventing the wheel. Look at [_str.join_](https://docs.python.org/3.5/library/stdtypes.html?highlight=str.join#str.join).
More
Hi, look at
1. [__collections.Counter__](https://docs.python.org/3.5/library/collections.html?highlight=counter#collections.Counter).
2. the [_filter()_](https://docs.python.org/3.5/library/functions.html?highlight=filter#filter) built-in function.
3. the [_str.islower()_](https://docs.python.org/3
More
Hi, look at:
1. [_fractions.gcd()_](https://docs.python.org/3.5/library/fractions.html?highlight=fractions.gcd#fractions.gcd)
2. and [_functools.reduce()_](https://docs.python.org/3.5/library/functools.html?highlight=functools.reduce#functools.reduce).
More