CLEAN Python Sorting!! #python #programming #coding

preview_player
Показать описание
Sorting Python lists based off other objects.
Рекомендации по теме
Комментарии
Автор

I love your tutorials. Short and sweet, straight to the point, and understandable for beginner to intermediate coders.

capnryna
Автор

PEP-8 says NO to the backslash! And it's totally totally superfluous there, inside the brackets.

demitri_t
Автор

A better way is to use a lambda function for the key:

sorted(inventory, key=lambda i: rarity[i], reverse=True)

That way you avoid using any dunder methods.

xINuke
Автор

I know how to do it already, but I like these shorts of yours, so a suggestion for one to do in the future.

What if you want to reorder your inventory a bit. EG if one opened their item menu, Default display would put say healing items first, followed by damaging items... But then, we want firebombs to be the first item, followed by heals, and then the other damaging items.

Nikarus
Автор

Usually, the double underscore is ment for private attributes and methods. Python allows you to access them but is not a good idea to do so.

sorin.n
Автор

If you want the dict sorted and not just the list, you can use

sorted_inv_with_rarity = dict(sorted(rarity.items(), key = lambda x: x[1], reverse=True))

Then if you still need just the keys for sorted_inv, you can use or just sorted_inv_with_rarity.keys()

Great video.

XerosOfficial
Автор

Nice, but no need for a backslash inside function parens 😉

jacksonhall
Автор

You do not need to do \ in functions, you can just do func(args 1,
Args 2
, Args 3)

mgames
Автор

Brilliant tip, no BS. You've earned yourself a sub! 😅

Hyperlands
Автор

This seems like something fun for a text based game, which I’ve always wanted to do but never got around to

FirstNameLastName-ghiw
Автор

For readability, i think key=lambda item: rarity[item] is more obvious than getitem.

Trails
Автор

On laptop atleast we cannot see the results. Adjusting the length of your terminal much higher will definately help.

bilalmsd
Автор

Not me using lambda literally every time

josephvictory
Автор

Super valuable thanks buddy 👌 love your vids

SpacefootLife
Автор

You should use dict.get rather than the dunder method

crvlwanek
Автор

What is the your color scheme/theme??😂

MinhBui-hx
Автор

u can omit dunders and use just ".get"

uusserrrreesssuuu
Автор

bro, what keyboard is that, I need those crispy clacks in my life

kaidantheron
Автор

Why is there only 3 items in the output?

ladidaladida
Автор

What keyboard do you have it sound so nice?

thomasfox