About 371,000 results
Open links in new tab
  1. How can I use a Linked List in Python? - Stack Overflow

    Mar 3, 2017 · @MadPhysicist "It [deque] behaves like a linked list in almost every way, even if the name is different." — it is either wrong or meaningless: it is wrong because linked lists may provide different guarantees for time complexities e.g., you can remove an element (known position) from a linked list in O(1) while deque doesn't promise it (it is O(n)).

  2. python - Converting a list to a linked list - Stack Overflow

    Jul 22, 2015 · Reading the abstract/prototype, it looks like the creator of the problem wanted to solve this with recursive/dynamic programming methodology. This is a pretty standard recursive algorithm introduction. It's more about understanding how to write elegant recursive code more than creating linked-list in Python (not really useful or common).

  3. Python:Moving through linked list 'next' - Stack Overflow

    Remember, a linked list is a structure where each node's next property is a pointer to the next node. Your code is modifying the value of next, which is changing the structure of your linked list. When you process a linked list (in count_length, or in kth_to_last), what you want to do is point

  4. Linked List in Python- Append, Index, Insert, and Pop functions.

    Mar 9, 2014 · Implementing an insert method on a linked list on python. 1. Linked Lists - adding new node doesn't work. 0.

  5. Python Linked List Append - Stack Overflow

    Feb 4, 2015 · your append method works fine but it traverses the list until it finds the last node - which makes it O(n). If you keep track of the last node, you can make an append which is O(1): def append_O1(self, item): temp = Node(item) last …

  6. Reversing a linked list in python - Stack Overflow

    def reverseSll(ll_head): # if head of the linked list is empty then nothing to reverse if not ll_head: return False # if only one node, reverse of one node list is the same node if not ll_head.next: return ll_head else: second = ll_head.next # get the second node of the list ll_head.next = None # detach head node from the rest of the list ...

  7. How can I print all of the values of the nodes in my singly linked …

    Sep 20, 2016 · If I have created a linked list of nodes which have a value attribute, is there a way to print all value attributes for all nodes in the linked list using a while loop? [Edit] Also, how might I invoke the iter magic method so that I can iterate and print over the linked list? How also might I create a method that allows for additions, at the ...

  8. Linked lists and recursion in python - Stack Overflow

    May 9, 2018 · My question is regarding linked lists, I wrote a class for the linked list, what I need to do is to have a function with an input as a reference pointing towards the head of the list. 'linked_list.head' as I understand, with linked_list being the name of the list in question.

  9. arrays - How is Python's List Implemented? - Stack Overflow

    Oct 12, 2010 · @Kr0e I wouldn't say iterating over the list is as slow as linked lists, but that iterating over the values of the linked lists is a slow as a linked list, with the caveat that Fred mentioned. For example, iterating over a list to copy it to another one should be faster than a …

  10. python - Removing a node from a linked list - Stack Overflow

    Jan 11, 2011 · # Creating a class node where the value and pointer is stored # initialize the id and name parameter so it can be passed as Node(id, name) class Node: def __init__(self, id, name): # modify this class to take both id and name self.id = id self.name = name self.next = None # Create a class linkedlist to store the value in a node class LinkedList ...