useful interview data structures: heapq (intermediate) anthony explains

  Рет қаралды 3,634

anthonywritescode

anthonywritescode

Күн бұрын

today I show another useful interview datastructure -- heapq! I show how to use this to build a priority queue
playlist: • anthony explains
==========
twitch: / anthonywritescode
dicsord: / discord
twitter: / codewithanthony
github: github.com/asottile
stream github: github.com/anthonywritescode
I won't ask for subscriptions / likes / comments in videos but it really helps the channel. If you have any suggestions or things you'd like to see please comment below!

Пікірлер: 16
@limxunyi1823
@limxunyi1823 2 жыл бұрын
Recently found your channel from looking for help for advent of code questions, really love the explainations and look forward to binge watching a lot of your videos in the future!
@akshaymestry971
@akshaymestry971 2 жыл бұрын
I had to implement priority queue for processing videos at work, had used recipe by David Beazley from his Cookbook. The implementation was fine but explaining the heapq implementation to the colleagues during knowledge transference was a nightmare. Your explanation is easy to understand, will share this vid with peers.
@anthonywritescode
@anthonywritescode 2 жыл бұрын
glad it helps!
@LunaFlahy
@LunaFlahy Жыл бұрын
4:57 priorityqueue
@cakeinsauce
@cakeinsauce 2 жыл бұрын
Has anyone asked about contextvars in python? Curious to see the usage of them
@anthonywritescode
@anthonywritescode 2 жыл бұрын
I've had a few questions about contextvars and admittedly I haven't used them myself -- they're intended to be an asyncio aware thread local (so you'd really only use them if you've got global variables and need async / threadsafe access to them)
@kurianbenoy2
@kurianbenoy2 2 жыл бұрын
In interviews for what kind of questions is this data structure useful?
@anthonywritescode
@anthonywritescode 2 жыл бұрын
many popular algorithms require a priority queue -- for example dijkstra's
@muhammadsarimmehdi
@muhammadsarimmehdi 2 жыл бұрын
can you provide an example where heapq would be preferred over a standard list?
@anthonywritescode
@anthonywritescode 2 жыл бұрын
I show one in the video? but also heapsort or other heap-related algorithms perform much better without needing to continually re-shift the list items
@marsma18
@marsma18 2 жыл бұрын
And what 8f we have some workload which can have same priority? Can you continue on that topic.
@anthonywritescode
@anthonywritescode 2 жыл бұрын
if they have the same priority then it doesn't matter
@marsma18
@marsma18 2 жыл бұрын
@@anthonywritescode Like we have 4 task 2 with prio 1 and then 2 and 3. We cannot use heapq as i remember in easy way
@anthonywritescode
@anthonywritescode 2 жыл бұрын
should work fine, no modifications from what I showed in the video
@erwan5112
@erwan5112 2 жыл бұрын
So, heapq or queue.PriorityQueue?
@anthonywritescode
@anthonywritescode 2 жыл бұрын
good question, so the structures in `queue` are multiprocessing synchronized queues which are generally not what you want if you're just doing in-process work (they'll waste a lot of time locking / unlocking and setting up shared memory)
decorator typing (PEP 612) (intermediate - advanced) anthony explains #386
12:03
Heartwarming moment as priest rescues ceremony with kindness #shorts
00:33
Fabiosa Best Lifehacks
Рет қаралды 38 МЛН
Happy 4th of July 😂
00:12
Alyssa's Ways
Рет қаралды 67 МЛН
New model rc bird unboxing and testing
00:10
Ruhul Shorts
Рет қаралды 24 МЛН
Sigma girl and soap bubbles by Secret Vlog
00:37
Secret Vlog
Рет қаралды 6 МЛН
Heaps, heapsort, and priority queues - Inside code
19:01
Inside code
Рет қаралды 76 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 625 М.
Heapq Module And Priority Queue | Binary Heap | Python Tutorials
11:56
Amulya's Academy
Рет қаралды 29 М.
py-spy saved our python 3.11 rollout (intermediate) anthony explains #568
13:48
pesky reDOS and python 3.11 (intermediate) anthony explains #563
11:23
anthonywritescode
Рет қаралды 3,6 М.
Stacks and Queues (Python) - Data Structures and Algorithms
14:54
Unlocking your CPU cores in Python (multiprocessing)
12:16
mCoding
Рет қаралды 298 М.
prefer tuples to lists! (intermediate) anthony explains #564
6:39
anthonywritescode
Рет қаралды 9 М.
Смартфон УЛУЧШАЕТ ЗРЕНИЕ!?
0:41
ÉЖИ АКСЁНОВ
Рет қаралды 1,2 МЛН
Самый тонкий смартфон в мире!
0:55
Не шарю!
Рет қаралды 91 М.
Что делать если в телефон попала вода?
0:17
Лена Тропоцел
Рет қаралды 2,3 МЛН
Look, this is the 97th generation of the phone?
0:13
Edcers
Рет қаралды 5 МЛН
$1 vs $100,000 Slow Motion Camera!
0:44
Hafu Go
Рет қаралды 27 МЛН
Зачем ЭТО электрику? #секрет #прибор #энерголикбез
0:56
Александр Мальков
Рет қаралды 648 М.
EXEED VX 2024: Не өзгерді?
9:06
Oljas Oqas
Рет қаралды 49 М.