Python sort 🗄️

preview_player
Показать описание
Python sort sorting tutorial example explained

#python #sorting #sort

# -------------------------------------------------------------------
# sort() method = used with lists
# sort() function = used with iterables

students = (("Squidward", "F", 60),
("Sandy", "A", 33),
("Patrick","D", 36),
("Spongebob","B", 20),
("Mr.Krabs","C", 78))

grade = lambda grades:grades[1]
sorted_students = sorted(students,key=grade) # sorts and creates a new list

for i in sorted_students:
print(i)
# -------------------------------------------------------------------

music credits 🎼 :
===========================================================
Creative Commons — Attribution-ShareAlike 3.0 Unported— CC BY-SA 3.0
===========================================================
Рекомендации по теме
Комментарии
Автор

# sort() method = used with lists
# sort() function = used with iterables

students = (("Squidward", "F", 60),
("Sandy", "A", 33),
("Patrick", "D", 36),
("Spongebob", "B", 20),
("Mr.Krabs", "C", 78))

grade = lambda grades:grades[1]
# students.sort(key=age) # sorts current list
sorted_students = sorted(students, key=grade) # sorts and creates a new list

for i in sorted_students:
print(i)

BroCodez
Автор

He breaks down these complex topics into 3 minute videos!!
Truly Amazing

shamaeelahmed
Автор

Loving your videos, short but great explanation! thx for sharing your knowledge 🎉😊

CpTech
Автор

bro thank you i always learn things faster if i watch u

samirbekgozikulov
Автор

Honestly my brain went into the stupid mode when I was trying to digest the lambda function used to obtain the key by which the dataframe was going to be sorted

Honestly I am not up to speed with lambda, and found the function defined in the old way more readable and easier to understand, as per my workings below

# define a function to return a Series of items in a column (grades here), by which the Dataframe will be sorted

def grab_item(items):
return items[1] # the index number for grade items is 1



# now sort the DataFrame using the key 'grab_item' as established above

students.sort(key=grab_item)


# execute below for loop to print out the list of tuples, sorted by the grades column

for i in students:
print(i)


Output per below


('Sandy', 'A', 33)
('Spongebob', 'B', 20)
('Mr.Krabs', 'C', 78)
('Patrick', 'D', 36)
('Squidward', 'F', 60)

loveSG
Автор

I like the way I learned from you bro 😅❣️✌👌

armaji
Автор

Bruh thank you so much, i was thinking about this literally overnight, and suddenly found this video.

galonpanda
Автор

his only video ive ever thought he didnt explain well, guys, his human, get him lol

passportbro
Автор

So.... Functions and methods are different?

And, in the lambda function in 6:13 what exactly is ages and ages[2]? I mean, there is no defined list called ages...
Is that list of tuple passed there with alias ages?

And, can we create the key function normally? Like without the lambda operator?

Thanks!

PS: sorry for number and length of questions

qcdominates
Автор

You are my life saver 💕💕💕 thanks a lot bro🫴🫴💕💕

ANS-tm
Автор

I did it but i dont understand very well of lambda function

gamePlays
Автор

here's a comment for the algorithm bro ily

ilordepic