Natural Sorting with natsort in Python

preview_player
Показать описание
Today we learn how to do natural sorting with a package called natsort in Python.

◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚

💼 Services 💼

🌐 Social Media & Contact 🌐
Рекомендации по теме
Комментарии
Автор

Never heard about natsort. Thanks a lot!

djdawidoss
Автор

Great demo - useful set of utilities. Thanks.

paulthomas
Автор

Hey, thanks so much NeuralNine. This was perfect little video.

mjpender
Автор

Nice!
But, there are alternatives without imports:
sorted(nums_list, key= lambda x: int(x)) - will sort strings of numbers
or (in case of lists like one below)

feet_list = ['4 ft 2 in', '6 ft 3 in', '2 ft 3 in', '42 ft 5 in']

sorted(feet_list, key= lambda x: int(''.join(x.split()[::2])))

samoylov
Автор

Thanks!

I ran against a case where i needed this 2 days ago.

Walter_
Автор

Very useful package. Thank you for sharing.

nizamuddinshaikh
Автор

actually 6:35 ... why does it sort "Band" after "book"?
i wouldve sorted it: apple, banana, Band, book, ... bc of the following letters
is there a function that does this?

HeckslerGaming-pisy
Автор

> sorted_comm = humansorted( ['useless', 'wow', '🔥🔥', ] )
> print(sorted_comm)
> ['great video']

mihailazarescu
Автор

bro that's really helpfull tho!, Thanks

life_with_rauf