20
Ronnie Bathoorn
Last seen 2 years ago
Member for 4 years, 4 months, 4 days
Difficulty Normal
using list comprehension you can create the outer array as follows
out_array = [item for item in first_array if word in second_array]
that does exactly the same as:
out_array = []
for item in first_array:
if item in second_array:
out_array.append(item)
More
I like it
below line can be left out
root = roots.pop()
changing line 19 to this
q = deque(roots)
otherwise you are justing poping the root and then putting it back in a list
I created a FamilyTree class with an iterator base on your solution
https://py.checkio.org/mission/wrong-fami
More
I like your solution with the deviders list!
If you add empty string as the roman sign for 0 the -1 is no longer needed on the times index. Plus the "if times:" will also no longer be needed.
When roman_parts is a string you can add all parts with "roman_part += roman_codes[times]" and the join at
More
q, r = divmod(len(l),2)
allows you to calculate the // and % at the same time so you don't have to
recalculate them further down the program.
then you get:
l = sorted(data)
half, odd = divmod(len(l),2)
if odd == 1:
return l[half]
else:
return 0.5 * (l[half - 1] + l[
More
Did they add more test cases?
The solution did not work for me. It failed on the check with two fathers
I had to add the following check in the tree loop:
if anscestor[son]: return False # 'Can you have two fathers?'
More
since it only uses two standard python string functions i decided to put it in the clear category.
For clarity i will add an explanaition to the code of what is happening.
More
it appears that i cannot update my solution therefore i post the explanation here
Using maketrans we create a translation table where where each letter in str1 translates to a letter in str2 that is in the same spot in the string.
Now string.maketrans("abc","xyz") will translate a to b, b to y and
More
nice ad short and very readable. I didn't know about the rpartition
function. thanks!
More
i like it, but if i see it again in 6 months i will have to spend some time to understand it again
More
So that would make it:
sum(b"Chuck Norris Constant is greater than the sum of its parts",1)
More
could this be rewritten:
res.append(m)
res.append(int([k for k in dizio.keys() if dizio[k]==m][0])
)
res.reverse()
as this?
res.append(int([k for k in dizio.keys() if dizio[k]==m][0])
)
res.append(m)
More