We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
your solution works good. Nevertheless, you can improve it.
TL;DR
you can utilize list instead of queue. Your code will be 4x times faster. For big data it make sence.
In details
Keep in mind, that special data types like those provided by queue, give you extra features over built-in Python data types like list, set, tuple, dict, str. But this is not for free. More lines of code (inside queue objects) means more internal calls, means more time cost for trivial operations.
Thus, if you need only push and pop and only on the end of a list, then Python built-in list is the best solution.
The queue module implements multi-producer, multi-consumer queues. It is especially useful in threaded programming when information must be exchanged safely between multiple threads.
Happy pythoning !
😎
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 18: Queues and Stacks
You are viewing a single comment's thread. Return to all comments →
Hi Gregorz
your solution works good. Nevertheless, you can improve it.
TL;DR
you can utilize
list
instead ofqueue
. Your code will be 4x times faster. For big data it make sence.In details
Keep in mind, that special data types like those provided by
queue
, give you extra features over built-in Python data types like list, set, tuple, dict, str. But this is not for free. More lines of code (insidequeue
objects) means more internal calls, means more time cost for trivial operations.Thus, if you need only push and pop and only on the end of a list, then Python built-in
list
is the best solution.Then, when to use
queue
? RTFM:Happy pythoning !
😎