Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
None in the list error
#1
My excersise is to output list without occurring in the list.

I made it, but there is another condition which I do not really understand and it gives me an error.
Condition:
0 <= LinkedListNode[i].val <= 1000
def makelist(main = [3, 4, 3, 2, 6, 1, 2, 6]): return list(dict.fromkeys(main)) for x in makelist(): print(x)
Error:

TypeError: 'SinglyLinkedListNode' object is not iterable
Edit:
It seems that I have Null as an element how to work with that for example to delete it before it goes with dict.fromkeys?
Reply
#2
I made it:

def makelist(main = [3, 4, 3, 2, 6, 1, 2, None]): result = [] for x in main: if x != None: result.append(x) else: pass return list(dict.fromkeys(result)) for i in makelist(): print(i)
But unfortunately it doesn't work well on online compiler if you have any sugesstions, Thank you:)

for x in main: TypeError: 'SinglyLinkedListNode' object is not iterable
Reply
#3
The error message says there should be some code like this:
class SinglyLinkedListNode(): def __init__(self, value, nxt=None): self.val = value self.nxt = nxt x = SinglyLinkedListNode(1, SinglyLinkedListNode{2, SinglyLinkedListNode(3))) for link in x: print(x.val)
To fix the error you need to make the SinglyLinkedListNode class iterable.

If the error is really with this test:
0 <= LinkedListNode[i].val <= 1000
It means that SinglyLinkedListNode is trying to use an interator to implement __getitem__(self, index):
Reply


User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.