Загрузка...

Python Snippets - using the Bisect Module to Maintain Sorting Order in a List

This video demonstrates an efficient way to insert new elements into already-sorted lists in Python - while maintaining the sorting order - using the bisect module.

We use the bisect.insort() function to efficiently calculate, using a logarithmic binary search algorithm, the point of insertion for a new element.

We demonstrate this with a small list of English football teams - but bisect operations work best with large lists of thousands/millions of items.

☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
To support the channel and encourage new videos, please consider buying me a coffee here:
https://ko-fi.com/bugbytes

𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:
📖 Blog: https://www.bugbytes.io/posts/
👾 Github: https://github.com/bugbytes-io/notebooks/blob/main/python-standard-library/bisect.insort.ipynb
🐦 Twitter: https://twitter.com/bugbytesio

Видео Python Snippets - using the Bisect Module to Maintain Sorting Order in a List канала BugBytes
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять