40
Last seen 4 days ago
Member for 9 years, 10 months, 19 days
Difficulty Advanced
Hi, `list1` and `str1` are redundant:
return ''.join(re.findall('[A-Z]*', text))
More
Hi,
1. `&` means [_set intersection_](https://docs.python.org/3.4/library/stdtypes.html#set.intersection) in Python. Use `and` instead.
2. You could move line 10 inside the for loop and return the condition:
return number and lower and upper
More
Hi `x` is redundant:
return "".join(findall('[A-Z]', text))
P. S.: You can solve it without using __re__.
More
Hi, this is the same:
return firstWLcCounterList == secondWLcCounterList
is the same as:
if firstWLcCounterList == secondWLcCounterList:
return True
else:
return False
More
Hi,
1. `number/x == int(number/x)` ... ugh. Use `%` instead. Have a look at [this](https://docs.python.org/3.4/library/stdtypes.html#numeric-types-int-float-complex).
2. Line 16: `if not len(outputString):`
3. Have a look at other solution, this one is quite "overengineered"
More
Hi, have a look at _sum()_ and _extended slices_.
for w in range(0,len(array),2):
total += array[w]
# is the same as:
sum(array[::2])
More
Hi, `in` in Python is quite powerful:
if searchTerm in text: wordsFound += 1
# or even:
wordsFound += searchTerm in text
# or even shorter:
return sum(searchTerm in text for searchTerm in words)
More
Hi, `enumerate` is redundant:
for c in text:
...
You could use _filter()_ instead.
More
Hi, few things:
ad Line 2:
a = sorted(((x, abs(x)) for x in numbers_array), reverse=True)
But you actually don't need `a` and logic on line :
return sorted(numbers_array, key=abs)
More
Hi,
1. _bin()_ returns a __str__ therefore line 3 is redundant.
2. `b` is redundant. You can chain methods in Python.
return bin(number).count('1')
More
Hi,
1. there's a shorthand syntax for `R = R + 1` -> `R += 1`.
2. You could use _generator expression_ and _sum()_.
text = text.lower()
return sum(word in text for word in words)
More
Hi,
1. _str.isupper()_ return __bool__, therefore ` == True` on line 4 is redundant.
2. `text` is __str__, which is iterable:
for word in text: # This is
if word.isupper(): # a filter :)
S += w
return S
3. You could use _filter()_ and _str.join()_:
r
More
Hi,
1. _len()_ or _sum()_ would do a better job here.
2. `S`, `result` and especially `W` are redundant.
3. Lines 3, 9 and 10 represent and `if..else` which you don't need.
def checkio(words_set):
S = sum(word_2.endswith(word_1) for word_1 in words_set for word_2 in words_set)
More
Hi, look at slices, _map()_ and _all()_ and _any()_.
def checkio(words):
s=words.split(' ')
for i in range(len(s)-2):
if all(map(str.isalpha, s[i:i+3])):
return True
return False
# or:
def checkio(words):
s=words.split(' ')
More
Hi,
1. Why not `str(number)` instead of `string='{}'.format(number)`.
2. I'm sorry but, lines 5-7 are so funny :)
for i in string:
if not i == '0':
result *= int(i)
# or even:
for i in str(number):
if not i == '0':
result *= int(i)
3. Look at
More
Hi, you don't need the ...if..else:
return re.match("^(?=.*[a-z])(?=.*[A-Z])(?=.+[0-9]).{10,}$",data)
# or if you want:
return bool(re.match("^(?=.*[a-z])(?=.*[A-Z])(?=.+[0-9]).{10,}$",data))
More
Hi, the last if is redundant:
return length >= 10 and contains_lower and contains_upper and contains_digit
If data is to short you don't need to continue:
if len(data) < 10:
return False
etc.
Shortened version:
def checkio(data):
if len(data) < 10: return False
More
One-liner:
checkio = lambda data: len(data) >= 10 and all(map(set(data).__and__, map(set, (string.ascii_lowercase, string.ascii_uppercase, string.digits))))
More