

In this video we will be learning how to sort lists, tuples, and other objects in Python. We will start by performing simple sorts on a list of integers and then move on to slightly more advanced sorting using custom criteria. Let’s get started.
✅ Support My Channel Through Patreon:
✅ Become a Channel Member:
✅ One-Time Contribution Through PayPal:
✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey’s Public Amazon Wishlist
✅ Equipment I Use and Books I Recommend:
▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –
#Python
source
@Corey Schafer
First of all thank you for the videos and the amazing explanations!!! They have been a wonder. I would like to however find out what settings or packages you use to get the info on what it is that you are typing when coding. For example in this video at 0.56 while you are typing " s_li "…. it indicates that it is a statement. I have also seen that it does this for keywords and others as well. I have watched your video in configuring sublime text for python and have added the packages that work for me and have done the settings, however those settings have not added this functionality. Could you point me in the right direction so i can configure my sublime text to allow for this? Thank you
sum of digits of a number until sum becomes single digit_pl make a video on that
The ease with which this person writes the code is ultra classy. I can only wish I had the knowledge as superior as Corey's.
2:07 should be “sort” method, not “sorted”
on the function "e_sort()", how does salary, age or name is returned from the class?
how is he printing without paranthesis ?
anyone …
Hey friend! Thx for you work. Can you explain me how do you delete # symbol in SublimeText with a single click? I use mac OS and I Don't know the hotkeys to delete symbols in the few string at once
Hello,
Why we use init and repr as _init_ and __repr__… What is the logic behind putting the _ before and after them?
Hey everybody, how's it going in comment section?
I want to know how can I sort values in dictionary.
sorry i wanna ask, can i sorting value of list without change an index
Thank you Corey for your time and effort. Keep spreading the knowledge.
Is there a video that explains what "class" is and what _init_ means?
Hello Corey, you've been doing a great job helping people to gain tremendous amount of knowledge, I will certainly make a huge contribution to your channel once I find a job as a python developer.
Also, I have one suggestion …..
Why not release your compiled course on Udemy, its a huge community and it would help you earn well as each student purchases your course.
Cheers
God bless you brother
Lots of respects to you from India
I've got this list called r and I have to sort it in a function. If I use r.sort() or t = sort(r) it's still not sorted.
Can somebody explain to me why that is and how to fix it?
So with sorting objects what if the age is the same integer value, how can we switch it to sort based on the name alphabetically
done 9/9/19
You didn't assign anything to emp, how does computer know what emp is?
Amazing. Thanks to you, I have learned so much when I discovered your channel. My grandpa had told me a long time ago: "Knowing how to do something
is not valuable, but knowing how to do something and why to do this in such a way is.". You give us pure knowledge. Thank you.
How do you match or intersection two multidimensional list of a list
Great vid. How about a video on linked-list vs. arrays, and sort algorithms?
Hey Corey, I need to sort two arrays
1. contains the chemical reactions
2.sensitivity values
The array is the size of 325. I was unable to solve that can u please me out?
I will be glad if u reply to my comment
Thanks
For those reading the comments: this channel is a goldmine!
you are the best, you help me a lot TNX.
Hi, thank you for all your videos. How do you comments out a line or several lines?
Hello Corey,
These videos are fantastic and I am learning so much so thank you for posting them. I hope you are still monitoring them because I have a question. I was attempting to sort a dictionary by its values rather than its keys and I am getting some errors. My original dictionary was structured as {string:string} and when I attempted to sort it I received the following error: TypeError: '<' not supported between instances of 'int' and 'str'. I then created a new dict with {string:int} and the sorting worked fine. I searched for the issue but every example has a dictionary with {string:int}. I am at a loss as to how to sort a dictionary with {string:string}, am I missing something very simple. I used the following sort methods: sorted_dict = sorted(dict_01.items(), key=operator.itemgetter(1)) and sorted_dict = sorted(dict_01.items(), key=lambda x: x[1]). Appreciate any insight you could offer!!
I am wondering if you should create a companion video for multiple key sort.
you are amazing, thanks for these awesome videos
How he is removing hash '#' in just one click?
Hi sir I use Pycharm for coding, but some keyword are not defined, and I try to use sublime text also but it still don't work. e.g print nums # which don't have parentheses.
If anyone needs the source code of last example:
class Employee:
def __init__(self, name, age, salary):
self.name = name
self.age = age
self.salary = salary
def __repr__(self):
return '({}, {}, {})'.format(self.name, self.age, self.salary)
e1 = Employee("Carl", 37, 70000)
e2 = Employee("Sarah", 29, 80000)
e3 = Employee("John", 43, 90000)
employees = [e1, e2, e3]
# def byName(emp):
# return emp.name
# you can sort by age and salary by returning:
# return emp.age
# return emp.salary
s_employees = sorted(employees, key=lambda e: e.salary, reverse=True)
print(s_employees)
# or
class Employee:
def __init__(self, name, age, salary):
self.name = name
self.age = age
self.salary = salary
def __repr__(self):
return '({}, {}, {})'.format(self.name, self.age, self.salary)
e1 = Employee("Carl", 37, 70000)
e2 = Employee("Sarah", 29, 80000)
e3 = Employee("John", 43, 90000)
employees = [e1, e2, e3]
from operator import attrgetter
s_employees = sorted(employees, key=attrgetter("salary"), reverse=True)
print(s_employees)
very concise and to the point. thank you sir
If I had a large data set with many attributes, is there a way that I could turn them all into objects in bulk, so that I could then proceed to sorting the data in a certain way?
can any1 plzz tell me where is e_sort() is called and how emp is passed as a argument
key=lambda x: x.salary
edit: lol i just realized i only watched half the video.. and now you are showing the lambda function haha
Thank you very much, mate! This video really helped me!
0:18 "a custom criteria" ? criteria = plural of criterion
I wonder how can someone dislike these tutorials
If you want name as primary sort and then age as secondary sort…how would you do that?
This is a lot of stuff!
Loving the series and wanted to say thank you for putting this out. I noticed due to a typo in my hand typing/copying the code and running it that it is worth mentioning that like other languages I have looked at (which would be just barely getting into C and basic) that sorting strings is based upon the ASCII set, which means that sorting the words 'OS' and 'age' due to lowercase being higher numbered the 'age' string is returned after the 'OS' string. These videos are awesome, TY again for doing this