Isn’t it because list is linked list, so to get the Len it has to iterate over the whole list whereas to get emptyness it just have to check if there is a 1st element ?
I comment because this is how a social network works, and this is how you keep lemmy alive. My comment has generated a dozen of other comments, so he achieved his goal.
There is not a single question that’s already have been answered on internet, so there no point on asking anything on social plateforms except just for the sake of interacting with other peoples.
If the point of Lemmy is just to generate as many comments as possible with everyone just assuming whatever they want about linked articles without reading them I’ll quickly leave again. I’m here for informed discussion, not for a competition in generating engagement
Don’t know how list are implemented in Python. But in the dumb linked list implementation (like C++ std::list), each element has a “next” member that point the the next element. So, to have list length, you have to do (pseudo code, not actual python code):
len = 0
elt = list.fisrt
while exist(elt):
elt = elt.nextlen++
returnlen
Whereas to test if list is empty, you just have to:
Isn’t it because list is linked list, so to get the Len it has to iterate over the whole list whereas to get emptyness it just have to check if there is a 1st element ?
I’ too lazy to read the article BTW.
why comment if you don’t even want to read the article? python lists are not linked lists, they’re contiguous with a smart growth strategy.
I comment because this is how a social network works, and this is how you keep lemmy alive. My comment has generated a dozen of other comments, so he achieved his goal.
There is not a single question that’s already have been answered on internet, so there no point on asking anything on social plateforms except just for the sake of interacting with other peoples.
Lemmy is not stackoverflow 😉
If the point of Lemmy is just to generate as many comments as possible with everyone just assuming whatever they want about linked articles without reading them I’ll quickly leave again. I’m here for informed discussion, not for a competition in generating engagement
So… it has to iterate over the whole empty list is what you’re saying? like once for every of the zero items in the list?
Don’t know how list are implemented in Python. But in the dumb linked list implementation (like C++ std::list), each element has a “next” member that point the the next element. So, to have list length, you have to do (pseudo code, not actual python code):
len = 0 elt = list.fisrt while exist(elt): elt = elt.next len++ return len
Whereas to test if list is empty, you just have to:
return exist(list.first)
That’s exactly what I was getting at. Getting length of an empty list would not even enter the loop.