#๐Ÿ”’ LinkedList Implementation

30 messages ยท Page 1 of 1 (latest)

hallow needleBOT
#

@crimson basin

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

amber frost
#

!paste

hallow needleBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

loud saffron
#

..

crimson basin
amber frost
crimson basin
#

code review

robust ravine
split surge
loud saffron
robust ravine
split surge
robust ravine
#

@crimson basin you can rewrite is_empty to be more concise

split surge
#

True

#

was gonna say that

amber frost
# crimson basin code review

You don't need to annotate the return of __init__ since it must be None. Try to also be consistent with your spacing of annotations.

Other than that, looks pretty standard. Instead of a print_all_nodes method though, I'd implement __iter__ to make this a proper iterable, and then just let the user iterate over the list themselves.

#

Implementing a proper iterable is a good exercise as well since it teaches you how iterables and iterators work, which is pretty important.

crimson basin
#

thank you for your quick reviews, i was afraid that my code might have major bugs

split surge
#

Also your append method wouldn't work well

#

Your linked list will only end up having 2 nodes with that code

#

And it'll just end up overwriting the second node when you try to append a third one

crimson basin
#

i tested with for loop of range 20 it worked fine

split surge
#

Oh

#

ohh mb

crimson basin
#
new_list = LinkedList()
for i in range(1,21):
    new_list.append(i)
print("--> Before Deleting <--")
new_list.print_all_nodes()
new_list.pop_tail()
print("--> After Deleting <--")
new_list.print_all_nodes()
golden hull
#

is size a requirement?

#

it would make more sense to follow the __len__ protocol

golden hull
hallow needleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.