What operations does your linked list implement? Use those to build it from the python list.
Presumably you’d start out with empty and append each value, no? And depending on how exactly your links work you might want to start either from the front or the back of the list.
And arguably that’s something the linked list’s
__init__ should or at least could be doing (but then you would need a class for your linked list, you don’t have that, you only have a class for a node… you could consider a node to be a linked list (this is reasonable) but that would not be the nicest ever interface to expose the list with, so a containing type might be nice)
In particular there’s a clash when creating a list, if a ListNode is a list, then creating a list would be done by calling ListNode but then how do you create a single node … doesn’t entirely add up
Uhm. keep in mind that your structure is different from that of a python list. If you keep the whole list then you do not have your structure, so no, that wouldn’t be a linked list would it?
Keep in mind that the purpose of creating a linked list type is to expose operations. It is through them that you would do the conversion. And it is through them that you would use the list. And using a list probably involves creating lists.