This solution maybe clever, but as for me it's unreadable.
PEP8 recommended max line length is 79.
So I think it shouldn't be considered as best practice.
Check the solution from @bidouille. I liked it.
It doesn't recreate the whole list. It recurses through the list until it finds the correct index, then inserts the new Node at that location. If you're referring to head.next = insert_nth(head.next, index - 1, data), that doesn't "recreate" anything, it just sets the new assignment which, in most cases, is the same as the old assignment.
If the linked list contains that many elements, then this function will fail. However, lists of that size were not part of this kata. That being said, if I wrote this again, I'd make it tail recursive, and then the list size would not be limited by the stack size.
Could anyone explain why this solution is 'Best Practice'?
Looks like we conplitely recreate whole list here instead of adding the needed element into the index position.
What if the linked list contains 1500 elements? Won't we get the RecursionError?
awesome solution!
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Yeah, that combination is really best! Thank you for the update :)
Yes and no.
So in the end, the actual best practice would be to combine both approaches.
This solution maybe clever, but as for me it's unreadable.
PEP8 recommended max line length is 79.
So I think it shouldn't be considered as best practice.
Check the solution from @bidouille. I liked it.
Really nice solution. However truncating hello to hell makes it weird
got it. Thank you @Azuaron for explanation!
It doesn't recreate the whole list. It recurses through the list until it finds the correct index, then inserts the new Node at that location. If you're referring to
head.next = insert_nth(head.next, index - 1, data)
, that doesn't "recreate" anything, it just sets the new assignment which, in most cases, is the same as the old assignment.If the linked list contains that many elements, then this function will fail. However, lists of that size were not part of this kata. That being said, if I wrote this again, I'd make it tail recursive, and then the list size would not be limited by the stack size.
nice Square subclassing :)
I like BeautifulSoup better
Could anyone explain why this solution is 'Best Practice'?
Looks like we conplitely recreate whole list here instead of adding the needed element into the index position.
What if the linked list contains 1500 elements? Won't we get the RecursionError?
Loading more items...