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.
Ranked 6 now. Too high for that also.
Definitely overranked, but it can't be changed anymore.
Hi,
if nums.count(0) > 1:
is my mistake. In my solution, I reuse thezeros
.filter(None, iterable)
is an idiomatic use described in the Python documentation (see here).@FArekkusu:
(foo(x) for x in arr)
is a generator expression and it returns a generator too.Regards,
suic
My code looks like the way it does because it's easier and shorter to write.
What?..
It's always a good practice to use
try-except
block if you know what you're doing-_-
It could easily be worse than
O(4n)
because you're searching for0
's index inside your list comprehension. Twice.Your speech about Python's functional language features are wrong. Python is not functional because lambda's are restricted to one-line functions. Moreover,
map
lets you apply a pre-defined function to the array elements using a very concise syntax -map(foo, arr)
instead of(foo(x) for x in arr)
, and it also returns a generator instead of the whole list which is a big advantage when you can't waste memory. The same applies tofilter
.And again you don't know when it's better to use
filter
. For simple situations list comprehensions are a lot better choice.And regarding being pythonic - the truly pythonic code is
[x for x in arr if x]
(or alternativelyfilter(lambda x: x, arr)
).Don't assume stuff out of nowhere. I haven't said anywhere which option I prefer. In fact, I prefer neither one as an empty array would be an incorrect input.
You should post a link to the solution. No sane person will spend their time scrolling through thousands of code snippets to see that there're wrong solutions which do not work properly.
The third test case makes no sense. Technically, the result is "YES" as he doesn't get into a situation where he can't give the correct change. On the other hand, the answer is "NO" because there're no customers to sell tickets to...