15
sakura usagi
Last seen 2 months ago
Member for 3 years, 6 months, 11 days
Difficulty Normal
I didn't know that the lambda expressions can use default values like ```c=lambda x:set(x.split(","))``` !
Thank you! xd
More
for those who come to this solution later.
the trick of
return text.split(begin)[-1].split(end)[0]
under the condition that begin/end may not in the text.
text = "Hello"
text.split("Not In The Text")
# ->["Hello"]
More
don't work for me....
maybe the test cases had been changed.
Now, c.swapcase() is do the work.
More
I think it will not work if l[0] is 0.
But I did not know "itertools.compress", so thank you for sharing the function.
More
I think string like **" 'example' "** should be matched according to description. ;)
re.search("[a-zA-Z']+", text)
More
As you may know, your code can be shortened:
for x in els:
if isinstance(x, tuple):
all_tuple_list += [x]
else:
all_tuple_list += [(x, 1)]
==>
all_tuple_list = [x if isinstance(x, tuple) else (x,1) for x in els]
btw, the code from line 39-56 was written in a way
More
Ah, I was you....
But same as mine, your code have bug (in line 7) which you cant delete 0s if there is negative item.
And I think there is no statement that items of given list are all positive. (although there is no test with negatives)
More
Is this right?:
len(max(t)) # in line 4
I think you need the max length of lines, but
max(["ebc", "abcd"]) == 'ebc'
Seems max(len(t)) is more applicable.
More
hmm, this has a problem when same items are in a text.
like:
text = "ababababab"
your code return : 'BBBBB'
Gold answer is : "BbBbB"
More
It is easy to read, but ">" itself returns bool, so you can write that much short:
return len(password)>6
More
I think some part of the code (line7-8, 15-16, 10-11) is needless, but still good solution.
More
No need to escape by yourself, recommendation is to use re.escape():
import re
tokens_to_escape = r"\w[]()|"
# tokens_to_escape = '\\w[]()|'
escaped_tokens = re.escape(tokens_to_escape)
# escaped_tokens = '\\\\w\\[\\]\\(\\)\\|'
and you can use the escaped string directly int
More
It's much simple :
return len(password) > 6
because ">" operator itself returns boolean.
More
Let:
text = "a b c d"
if we use str.split() with no args:
text.split()
# -> ["a", "b", "c", "d"]
if we use str.split() with sep = " ":
text.split(" ")
# -> ['a', 'b', '', 'c', '', '', '', '', '', 'd']
More
FYI: String is iterable
for i in list(text):
is same as
for i in text:
More
line 3: we should not use range if index itself doesn't have meaning.
for char in number:
is better.
line 4: number is already string.
More