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.
Could you enlighten me? Pretty please?
OOOOH THATS SO USEFUL THANKS A LOT!
Python list slicing works like this:
list[start:stop:step]
Where
start
is the first index to visit,stop
is the index before which we will stop, andstep
is how far to move at each step of the process.When
start
isn't specified it defaults to 0, and whenstop
isn't specified it means we take the entire list afterstart
. Whenstep
isn't specified it also defaults to 1.Putting this all together,
list[::-1]
means "take the entire list, stepping backwards" - or, in simpler terms, reverse it!Super Cool Solution! I haven't seen that "[::-1]" thing before can someone explain what that is plz?
ChatGPT solution if you ask it to do it in one line.
The difference is that with the reversed method you get a result that you still need to convert to something so you can use it later on in the code. With the ::-1 method you get a final result that is ready to be used in your code, with this method you get a final result, with the reversed you get a tool to use.
Practice practice and some more practice. Make sure to make time for some more practice in between. You won't even realize when you have started writing code like this...
oh I just learned how to use "not in" recently but I forgot to apply it.
The most important thing here is the list comprehension (sum(int(x)) for x in str(value)
It is nothing but a for loop, you will write hundreds of for loops until it just clicks that what you're trying to do is this essential form, and then it comes naturally.
the more you see it the more obvious it gets
same here LOL
thats clever
when using list comprehensions, if you have no else to add, you should use the if after the for not before it. I guess that's the reason
try it yourself.
This reply might make sense if you used modulo extraction to do it completely mathematically, but you used a method that is still O(n) in space complexity so the difference between your code and the given solution is barely different.
This isn't quite correct. That isn't a list expression, its a lazy generator. There is no intermediate list of 1s created, rather it yeilds a 1 each time it is requested by the sum function.
I am still new to python but I wonder how does someone think about these one liner clean code, does it come after few iterations or they pop up just like that :)
Loading more items...