Python Tutorials - List Sorting | sort method

  Рет қаралды 93,448

Amulya's Academy

Amulya's Academy

6 жыл бұрын

In this Python programming video tutorial we will learn how to sort list using sort method in detail.
sort is a built in method which will modify original list and arrange elements in ascending or descending order.
Syntax of sort method is:
list_name.sort(key = None , reverse = false)
Here in this tutorial we will discuss about key function and reverse in detail with example.
For more free tutorials on computer programming
/ amulsacademy
/ amulsacademy

Пікірлер: 120
@babyfox205
@babyfox205 4 жыл бұрын
great explanation of the 'key' for sorting, your explanation was the best of all 5-6 that I've seen today and were unable to really understand why we can put any function into the key. Thank you!
@fatinishraqprapya3139
@fatinishraqprapya3139 2 жыл бұрын
This is one of the best helpful video for the beginners who are learning Python.
@angelomichel6074
@angelomichel6074 4 жыл бұрын
this information is so satisfying !!!Thank you so much Amuls Academy
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
Glad you liked it!
@sushilkumar-ef7gh
@sushilkumar-ef7gh 5 жыл бұрын
I have to say that you have made coding more interesting then ever for me ....Thanks a lot
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Welcome:)
@alimujtaba1208
@alimujtaba1208 2 жыл бұрын
your teaching method is very best i satisfier
@sairamnagarajan8289
@sairamnagarajan8289 5 жыл бұрын
Simplistic explanation. Thanks for your effort.
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
My Pleasure :)
@zhimwar1367
@zhimwar1367 5 жыл бұрын
Thank you so much for sharing this. U have solved one big question in head for long time.
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Pleasure :) And that is ?
@Suhail_202k
@Suhail_202k Жыл бұрын
Really one of the best videos on KZbin hatsoff ,great explanation mam thanks for your efforts,i hope you will do more videos ❤
@qzorn4440
@qzorn4440 5 жыл бұрын
this is sooo relaxing python information. I listen to your video on my coffee break to relax. S*) thanks
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Welcome :)
@denizyarar4781
@denizyarar4781 3 жыл бұрын
thank you i'm a year 11 student writing code for an NEA and this vid is a lifesaver
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you :)
@gani3676
@gani3676 6 жыл бұрын
Hi Amul, Will be waiting for continuous video. Thanks
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
Thank you:)
@HarshRaj-bm9eg
@HarshRaj-bm9eg 5 жыл бұрын
thank you very much for making such a very beautiful video based on python
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Thank you:) Keep Learning
@mohsharma3937
@mohsharma3937 3 жыл бұрын
THANK YOU SO MUCH MA'AM YOU CLEARED MY DOUBT
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
It's my pleasure : )
@HarshRaj-bm9eg
@HarshRaj-bm9eg 5 жыл бұрын
mam i am so so so thankful to u. you cannot even imagine what you are to me
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Welcome:)
@trishulsingh2907
@trishulsingh2907 2 жыл бұрын
Your channel is Underrated . Keep going one day you will reach 10k Subscribers .
@vishnubhardwaj2595
@vishnubhardwaj2595 3 жыл бұрын
your voice is really very soothing and video is very helpful.
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊
@sangeethaagoudar2175
@sangeethaagoudar2175 Жыл бұрын
This is one of the best video of knowing exactly how the nested list worked with sort .Thank you so much 😊
@steveaman5126
@steveaman5126 3 жыл бұрын
nice in-depth knowledge
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊
@AkashSingha
@AkashSingha 5 жыл бұрын
Thank you very Much mam it helps me a lot.
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Pleasure :)
@nagapurisandeep2289
@nagapurisandeep2289 3 жыл бұрын
Your explanation is good mam.
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊
@abdullakhan4632
@abdullakhan4632 4 жыл бұрын
very good. i like your explanation. grate 👍👍👍
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
Thanks! 😃
@saumyachaudhary3983
@saumyachaudhary3983 4 жыл бұрын
very good explanation
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
Thank you :)
@belalibrahim3812
@belalibrahim3812 4 жыл бұрын
Its soo helpful 😊
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
Thank you :)
@josephdzn9868
@josephdzn9868 5 жыл бұрын
good explanation. 2nd example can also be done by: list2.sort(key=lambda x: x[1])
@ilzz9856
@ilzz9856 3 жыл бұрын
Hi bro can u explain working of that expression?
@josephdzn9868
@josephdzn9868 3 жыл бұрын
I am not an expert here (still learning) but you can think of lambda as a throw away function. No need to define a separate function but you can encapsulate expressions (and arguments) using lambda - if that makes sense. Amulya's channel clearly explains the Lamdba function, check that out.
@mananbhatia9242
@mananbhatia9242 Жыл бұрын
how we can do to descending order using this function?
@allenjr4978
@allenjr4978 3 жыл бұрын
The best ever
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you 😊
@spark561
@spark561 5 жыл бұрын
This is a great video and more useful for us
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
Thank you :)
@spark561
@spark561 5 жыл бұрын
@@AmulsAcademy well come
@gouthamrajesh2745
@gouthamrajesh2745 3 жыл бұрын
Helped me in python project
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Glad to hear that :)
@subrinalazad3215
@subrinalazad3215 4 жыл бұрын
Thank you
@fun-ih5sc
@fun-ih5sc 4 жыл бұрын
9:18 . * When we call the userdefine function we are not passing any argument as but when you define the function it is taking one argument .How is it working. * key=SortBySec, here how the argument in function defination "Element" is pointing toward every index of a list Thanks & Regards Aditya
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
you should mention function name as key, no need to mention arguments. when you define key function it should contain only one parameter, if it contains more we will get error. when we use sort function it will take the first value of list and compare it with second element and based on the comparison it will sort the list. [when key is not mentioned]. when key is mentioned then instead of comparing first element with second, it will pass that first element to that function, next second element to that function later based on that function result it will sort the list. :)
@miftahshidqirabbani6489
@miftahshidqirabbani6489 3 жыл бұрын
Thanks dude. You helped me to get out of this :)
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Glad to hear that :)
@patelhardik2505
@patelhardik2505 3 жыл бұрын
thank you.
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Welcome :)
@itachi99887
@itachi99887 Жыл бұрын
Do you have any video on how to sort tuple inside list . For eg [(as,1),(cs,2),(bs,6)] how to sort the key value in ascending order. If you have please give the link . Thank you
@miraatif9945
@miraatif9945 5 жыл бұрын
Thanks mam
@ilzz9856
@ilzz9856 3 жыл бұрын
In the video you done ascending order through first element and by second element . How can we make descending order in that list with second elements?
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
take reverse=True :)
@deepuvarma9459
@deepuvarma9459 6 жыл бұрын
good one
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
Thank you:)
@1mol831
@1mol831 2 жыл бұрын
Thanks, though I still want to learn how I could sort by frequency. Without using a while loop with a dictionary..
@abhishekjaiswal3821
@abhishekjaiswal3821 4 жыл бұрын
thnx
@vignesh3851
@vignesh3851 Жыл бұрын
Your voice is melted me 🥶
@gauravpatil7977
@gauravpatil7977 2 жыл бұрын
how come index of second element is one in nested list? it should be element[0][1], shouldn't it ?
@amirsharifi8837
@amirsharifi8837 2 жыл бұрын
wow!
@HarshRaj-bm9eg
@HarshRaj-bm9eg 5 жыл бұрын
mam one more thing i want to say to you is that can you tell me that from where can i get questions based on python for beginners as i am new to program. this is the first time i am learning any language and this is the python
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
google it, you can start with basic programs:)
@sigdyxc2658
@sigdyxc2658 2 жыл бұрын
I like your voice
@debojitmandal8670
@debojitmandal8670 3 жыл бұрын
Mam can you sort length of a string and pritn the longest word
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
We can try :)
@krishk4870
@krishk4870 4 жыл бұрын
hey i got doubt pls clear it... that in 7:55 how the fucn (sortbysec) is works its just return the parameter(element's) first indexing position,that how could sort the list regards with sec value of sublist of list2 ????????? pls xplain the key fuction def sortbysec() plsssssssss amul !!!!!!!!!!
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
key function serves as a key for the sort comparison, it won't sort the list. "key" function transforms each element before comparison, next based on that transformed value sort() will sort the list. :)
@sanketh768
@sanketh768 4 жыл бұрын
Thanks for the video. But had 1 doubt which is still unclear def sortbysec(element):# accepts list as a parameter or argument return element[1] list=[(1,16),(1,2),(2,5)] list.sort(key=sortbysec)# my doubt is sort by sec is not taking any parameter as per the signature of this function. # we are not passing any argument to the sortbysec function i mean list2=sortbysec(list) # passing list as arguments Would greatly appreciate your help
@AmulsAcademy
@AmulsAcademy 4 жыл бұрын
No need to pass any parameter to key function :) You are calling list.sort(key) so whatever you will do with sort() will apply on list. :)
@sanketh768
@sanketh768 4 жыл бұрын
@@AmulsAcademy Thank you for the response
@bhagwatimehra4738
@bhagwatimehra4738 2 жыл бұрын
How to display a list in ascending and descending order using a str value
@Sandeep0917
@Sandeep0917 3 жыл бұрын
can u solve this by using for loop
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Give me the program, I will try :)
@mominumar3388
@mominumar3388 5 жыл бұрын
How can we sort a list containing numbers as well as characters??
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
In python 3 it will give error But you can separately sort characters and numbers then you can append it to list. c = ['s', 'a',2 , 'j', 9, 'e', 11, 't', 'k', 12, 'q'] c = sorted([i for i in c if not str(i).isdigit()]) + sorted([i for i in c if str(i).isdigit()]) print(c) :)
@Aivin
@Aivin 3 жыл бұрын
helpful helpful helpful did i forget to say helpful?
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you :)
@charancharan2417
@charancharan2417 6 жыл бұрын
Hi mam Will you provide online training or classroom training for python....???? May I know if you are doing training
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
No sorry:)
@nadeeshandilusha1934
@nadeeshandilusha1934 3 жыл бұрын
🖤🖤
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
😊
@tanmoysardar3908
@tanmoysardar3908 6 жыл бұрын
maam i am Tanmoy have been waiting for u since last week plz maam its very urgent i want to study that python graphics part ...i have subscribed your channel and also downloaded all of your video ..please maam make that video
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
Hi Sure. But i need some time:)
@tanmoysardar3908
@tanmoysardar3908 6 жыл бұрын
maam kya aap bata sakti how much you need maam isliye bol raha hu ki ek project submit karna tha thoda help ho jata
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
Project submit kab karna hai?? i need minimum 2 weeks. :)
@tanmoysardar3908
@tanmoysardar3908 6 жыл бұрын
4th of July maam
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
Ohhh...I guess i can't upload so early:)
@charancharan2417
@charancharan2417 6 жыл бұрын
Hi Please upload Django course for freshers
@AmulsAcademy
@AmulsAcademy 6 жыл бұрын
For now i can't. But will do tutorials on django:)
@swethamk5925
@swethamk5925 3 жыл бұрын
How to get a list input.. Like this [1,2,3,4] as an input and print it like [4,3,2,1]
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
You want to reverse the list or want to sort?
@swethamk5925
@swethamk5925 3 жыл бұрын
I want to reverse the list
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
list1.sort(reverse=True)
@madras.mp424
@madras.mp424 2 жыл бұрын
Where the without using built in function ?
@mathemediaworld9711
@mathemediaworld9711 5 жыл бұрын
Without using any build dunction
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
You can use selection sort or other sorting algorithms for that :)
@abhishekpathak9454
@abhishekpathak9454 4 жыл бұрын
Hllw mam my question is that how to get sum of sub list..?? Tell me plzz😓
@Aivin
@Aivin 3 жыл бұрын
sum(list[sublist]) i think
@Sanjaykumar-xr8rz
@Sanjaykumar-xr8rz 5 жыл бұрын
without function use kiye kro list ko assending order main
@AmulsAcademy
@AmulsAcademy 5 жыл бұрын
You mean to say without built_in functions ?
@tanaymajumder9220
@tanaymajumder9220 5 жыл бұрын
Amuls Academy please guide me to do without using sort function
@maltesh105joshi
@maltesh105joshi 9 ай бұрын
I have xml and i can sort within first child only. but it will through an error when the line have commented in my 1st child. it works fine if there is NO comments. can you help me here CODE root = tree.getroot() for c in root: c[:] = sorted(c, key=lambda child: (child.tag,child.get('name'))) xmlstr = ET.tostring(root, encoding="utf-8", method="xml") print(xmlstr.decode("utf-8")) ERROR c[:] = sorted(c, key=lambda child: (child.tag,child.get('name'))) TypeError: '
@mathemediaworld9711
@mathemediaworld9711 5 жыл бұрын
Do it
@Ganga_BE
@Ganga_BE Жыл бұрын
Sis. Input=1234, output=10203040 I want this program sis
@sensei_kail1109
@sensei_kail1109 3 жыл бұрын
nice india
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
Thank you :)
@TheNikhilify
@TheNikhilify 2 жыл бұрын
Virginal list
@sahals8564
@sahals8564 3 жыл бұрын
Thank you
@AmulsAcademy
@AmulsAcademy 3 жыл бұрын
You're welcome :)
Merge Sort in Python Programming | Program | Detailed Explanation
32:42
Amulya's Academy
Рет қаралды 96 М.
Children deceived dad #comedy
00:19
yuzvikii_family
Рет қаралды 7 МЛН
Получилось у Вики?😂 #хабибка
00:14
ХАБИБ
Рет қаралды 6 МЛН
I CAN’T BELIEVE I LOST 😱
00:46
Topper Guild
Рет қаралды 82 МЛН
Can You Draw A PERFECTLY Dotted Line?
00:55
Stokes Twins
Рет қаралды 86 МЛН
Python Tutorials - String Methods | translate() | maketrans()
16:26
Amulya's Academy
Рет қаралды 39 М.
Python Tutorials - Quick Sort Algorithm | Program | Part-1
27:51
Amulya's Academy
Рет қаралды 57 М.
Dictionary in Python
12:24
Telusko
Рет қаралды 1,3 МЛН
Python Tutorial - Map and Lambda Function
10:34
Amulya's Academy
Рет қаралды 91 М.
How to Use Lists in Python
18:49
Programming with Mosh
Рет қаралды 290 М.
Create Quiz Using Dictionary | Python Tutorials | Interview Question
18:25
Insertion Sort Algorithm - Theory + Code
30:40
Kunal Kushwaha
Рет қаралды 206 М.
Children deceived dad #comedy
00:19
yuzvikii_family
Рет қаралды 7 МЛН