Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
This comment is hidden because it contains spoiler information about the solution
I know this isn't supposed to necessarily be an efficient solution, but - the result of
arr[1:][::2]
is equivalent toarr[1::2]
andarr[0:][::2]
is equivalent toarr[::2]
. And if I'm not mistaken the latter options are also more efficient as you're not having to take two separate slices each time. Also inside your sum you can just use a generator rather than a list comprehension, ie. you don't need the surrounding[]
.It's called an absolute majority.
This comment is hidden because it contains spoiler information about the solution
Shortest O(n) solution that I can think of. Using
c.update([x])
inside a list comprehension is a bit horrid though!This comment is hidden because it contains spoiler information about the solution
It'd be better to replace
all([(n ** .5) in array1 for n in array2])
withall((n ** .5) in array1 for n in array2)
. The first unnecessarily constructs the whole list of booleans before passing it toall
. The second uses a generator expression, which means it gets the booleans lazily. If the the first value is False, thenall
will return False without ever bothering to get the rest of the values.Only just had a chance to look at this - looks like the ideal solution. Thanks for the recommendation on iterators - I haven't used itertools all that much so forget about how useful it can be.
Yes, Unnamed, you're entirely correct and this definitely should come under 'clever' rather than 'best practice'.
You're correct. I used just
[None]*len(keys)
for the sake of brevity, but ideally you'd use[None]*(len(keys) - len(values))
in practice.