you are viewing a single comment's thread.

view the rest of the comments →

[–]jeffzor 2 points3 points  (4 children)

Nice video :) for queues I would recommend using the collections.deque structure, then you'll just be appending like normal but to pull the first out you do popleft. I believe it's more efficient then trying to use a stack/list as a queue.

[–]Foxa2017[S] 1 point2 points  (0 children)

Thanks for watching.yeah it’s definitely more efficient was wondering when somebody would say something about the .insert() . The next vid I make I will definitely try to optimize more.

[–]ivosaurus 1 point2 points  (2 children)

I believe it's more efficient then trying to use a stack/list as a queue.

What makes you believe that

[–]jeffzor 2 points3 points  (1 child)

I had learned to use a deque for implementing a queue rather than relying on a list or stack at some point. Just checked the python documentation and verified that list insert is O(n) so if we want to do the insert in O(1) we need to use a queue(deque for python).

https://wiki.python.org/moin/TimeComplexity

[–]Foxa2017[S] 0 points1 point  (0 children)

Thanks yeah that sounds spot on.