Python Tutorials - Sorted Function | How to Sort List Tuple and Dictionaries
In this Python programming video tutorial we will learn how to sort list tuple dictionaries using sorted function in detail.
Sorted is builtin function can be used to sort iterables, which will return a new list with sorted elements.
Syntax of sorted function is:
sorted(iterables, 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
评论
مبدعه👍
Ma'am you are awesome thankyou ma'am 😘💖
Amulya's Academy
个月 前
Most welcome 😊
In reference to the key function, how does it know to skip the item at the next index so it sorts based on the letter? I.e. 'a' is at index [1] (which you put in the return statement) and then it sorts based on every item at every second index. So its sorting based on items at indexes [1] [3] [5 ][7] or does the indexing for each nested tuple start again? So the index number for each letter in the nested tuple is [1]? Also, I note that when you call the function in the sorted method you do not use parentheses at the end of the function I.e. normally when you call a function you put Secondvlaue(). Why is the parentheses at the end of the function not required when using it in the sorted function? Thanks. Good video btw.
Sherman Bernard
2 个月 前
@Amulya's Academy thanks. I still don't understand how the secondVlaue() function knows to call the second item in the first, and subsequent, nested tuples with the use of only one index. To call second item in the nested tuple, shouldn't it be [0] [1]?
Amulya's Academy
2 个月 前
Hey if i take nested list like this: list1 = [[1,2],[3,4]] if i want to access 1 then i need to take list1[0][0] because in list1 [1,2] list index is 0 [3,4] list index is 1. in the inner lists, list [1,2] index of 1 is 0 and 2 is 1. and also in list [3,4] index of 3 is 0 and 4 is 1. functions are called without parenthesis because parenthesis are added to key function inside the code written for sorted function. :)
Sherman Bernard
2 个月 前
Additional: I played around with indexing nested tuples and discovered that if you want to access a single item in a nested tuple you have to specify the index of the nested tuple and the index of the item in the nested tuple. I.e. [0][0] will retrurn item 1 from (1, 'a').
the way you say "tuple" is very sexy..
Mam, the function secondvalue is accepting one argument but when we are calling the function i.e used in key we are not passing any argument. Can u clarify my doubt.
eshwar vecham
7 个月 前
Ok mam thnks for ur reply. The function will be applied on each element of iterable? The secondvalue function is called as many times as the elements in iterable?
Amulya's Academy
7 个月 前
It will take iterable(the first value in the sorted(), list,dictionary,tuple) as argument to the function.
can u explain how key=lambda x:x[1] is working
AWESOME TUTORIAL BRUH, whats is ur age ??
Mam at 5.30 I can't understand here how lambda function works? Can you please explain me please mam 🙏
Amulya's Academy
9 个月 前
it will return the first element of the dictionary item.
Your explanation and voice is good to understand
Amulya's Academy
9 个月 前
Thank you :)
Hi Can we use sorted() for nested dictionaries? for ex cars = {"bmw":{"model":"rv10","Gear":"Auto","Year":2016},"Benz":{"model":"rv20","year":2019},'Audi':{"model":"rf30", "year":2019}} We can only use sorted() on keys. What if we want to do it for values and items?
which data structures can the key be used in? we can do the same in lists too right? Thanks for tips
thanks python is cool you can sort any data structure based on the index
Well explained. I am looking for this alsorted solution right now 👌👌
Amulya's Academy
年 前
Thank you :)
How to sort without inbuilt functions
Ashwini Dhole
年 前
Amuls Academy sure I will try. Could you please make us understand array manipulation problem like 5 3 1 3 100 2 4 100 3 5 100 Such that output should be 100 200 200 200 100
Amulya's Academy
年 前
You can use sorting algorithms. Bubble sort Merge sort ..... :)
Awesome explanation..
Amulya's Academy
年 前
Thank you :)
it is so clear OMG
Amulya's Academy
年 前
Thank you :)
Actually, nice
Amulya's Academy
年 前
Thank you :)
haha good job, I liked your explanations. Thank you for these tutorials!
dhanushka iroshan
3 个月 前
Awesome explanation ☺️
Amulya's Academy
年 前
Pleasure :)
Hello dear. Why defining function to manipulate items does not work for dictionary? Because we used it for tuple and list but not dictionary and instead you used lambda.
thank you for you nice video
Which mic do you use?
why you ding it in shell, and how can you print it???
You are a blessing. I couldn't understand the docs after being stunted on this code wars question www.codewars.com/kata/weight-for-weight. Thanks!
Super explanation.
Amulya's Academy
2 年 前
Thank you :)
Liked your videos a lot. Videos are very helpful for beginners.
Amulya's Academy
2 年 前
Thank you:)
well explained...thanks
Amulya's Academy
2 年 前
Thank you:)
Your voice is amazing and explanation also best
ROHIT kING
4 个月 前
Flirt yaha pe bhi😜😂
Amulya's Academy
2 年 前
Thank you:)
i have queries on python can u help me
innocent sahir
2 年 前
i have forwarded my query pls get to me asap
innocent sahir
2 年 前
waiting for your reply
Atif shaik
2 年 前
waiting to your reply pls contact me asap thanks
Atif shaik
2 年 前
Thanks
Amulya's Academy
2 年 前
amulsacademy@gmail.com
can you help with Memory Game programs and remote server using python
Waiting for some more videos and plz speak abut small project that will help lot of members
Amulya's Academy
2 年 前
Sure:)
maam have u done with that turtle graphics part
TANMOY SARDAR
2 年 前
Amuls Academy mam then will u post plz maam its urgent coding samajna hain mereko
Amulya's Academy
2 年 前
No:(
Mam will you teach Numpy, pandas, Matplotlib,scikit learn etc.. in the future videos😁
Rishi Sharma
2 年 前
Thanks mam
Amulya's Academy
2 年 前
Sure:)
If I post any queries in python then will you respond with answer
ThatControlUser WhoSucksAtPvP
2 天 前
@kurakula prashanth kwargs :/
kurakula prashanth
年 前
@Amulya's Academy you didn't passed the arguments to the function but you got the output how?
kurakula prashanth
年 前
How did you called that second value function without using parathesis like "**we should call like this na second value() ***""" Please reply mam. Waiting for your reply.
Amulya's Academy
2 年 前
yes:)
Amulya's Academy
2 年 前
yes:)