Do you know the bisect module in Python?

preview_player
Показать описание
Python Tip to insert items at the correct position. Do you know the bisect module in Python?

Get my Free NumPy Handbook:

📓 ML Notebooks available on Patreon:

If you enjoyed this video, please subscribe to the channel:

~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~

#Python
Рекомендации по теме
Комментарии
Автор

You can do everything in Python in 2 lines. As long as one of them starts with import

jomy-games
Автор

Want to build your own Tesla? Here's a python module !!

r.k_
Автор

a = [3, 5, 9, 11, 20]
value = 7
for i in range(len(a)):
if value <= a[i]:
a = a[:i] + [value]+ a[i:]
break
print(a)

nesky
Автор

Thank you for the to the point demonstration bc I just wanted to quickly know what bisect does and how to use it

winterfoxx
Автор

for i in range(len(a)):
if a[i] < value < a[i+1]:
a.insert(i, value)
print(a)

mal
Автор

Python would teach you the hard way of doing things and then teach you the hard way, I couldn’t believe I was using the (def) functions for arithmetic operations until I found lambda lol
And this one can be sorted with the variable.insert(index, value), enter, print variable

damilareadeesan
Автор

A simple way . Run binary search on the sorted array . That will give the index where it should inserted. Complexity : log(n)

haisomeone
Автор

In C++ you can use std::find(), which will return an iterator to the value or end() if the value doesn't exist. You can use this function for every iterable class, e.g. std::array or std::vector.

JammyCrazy
Автор

How to program in python....


Import everything

scravengerx
Автор

Bisect uses binary search alg so its good for time complexity

Nj-hwcv
Автор

Add number at the end and sort the list

Tom-Birdy
Автор

I thought ur gonna show us how to do it from scratch 💀

tomcsvan
Автор

Just wondering What ide are you using?

parsecscopeking
Автор

People who've done leetcode: No thanks 😂, it's just a simple binary search problem

jazzgirl
Автор

It suggest renamed into: "The Python programmer who is aware someone else has already solved the problema and made a library available."

NamasenITN
Автор

a.insert(2, value) :Well I didn’t exist here
Fun fact, this function only work for list but it doesn’t need any import

Taokyle
Автор

We don't need to import any module for this it's just a basic list function we can use append() for no specific index and insert() for specific index

ramananunboxing
Автор

Is this ever more effective than using a set for storage, adding it, and re-sorting it as a list if need-be (e.g. the default set sorting isn't how you want it to be, reversed or something)

jumper
Автор

Real problem here is that you are not using the proper collections, if you are gonna need to do this operations multiple time use a heap or something like that.

Baptistetriple
Автор

At this point you should probably just be using a heap

AngryArmadillo
visit shbcf.ru