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

评论

  • 1
    122 天 前

    مبدعه👍

  • Pooja Yadav
    Pooja Yadav个月 前

    Ma'am you are awesome thankyou ma'am 😘💖

  • Amulya's Academy

    Amulya's Academy

    个月 前

    Most welcome 😊

  • Sherman Bernard
    Sherman Bernard2 个月 前

    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

    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

    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

    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').

  • Holy Shazbat
    Holy Shazbat5 个月 前

    the way you say "tuple" is very sexy..

  • eshwar vecham
    eshwar vecham7 个月 前

    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

    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

    Amulya's Academy

    7 个月 前

    It will take iterable(the first value in the sorted(), list,dictionary,tuple) as argument to the function.

  • Indratej Reddy
    Indratej Reddy8 个月 前

    can u explain how key=lambda x:x[1] is working

  • Indratej Reddy
    Indratej Reddy8 个月 前

    AWESOME TUTORIAL BRUH, whats is ur age ??

  • Kushal Das
    Kushal Das9 个月 前

    Mam at 5.30 I can't understand here how lambda function works? Can you please explain me please mam 🙏

  • Amulya's Academy

    Amulya's Academy

    9 个月 前

    it will return the first element of the dictionary item.

  • Madhan B
    Madhan B9 个月 前

    Your explanation and voice is good to understand

  • Amulya's Academy

    Amulya's Academy

    9 个月 前

    Thank you :)

  • I kamesh
    I kamesh年 前

    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?

  • hello world
    hello world年 前

    which data structures can the key be used in? we can do the same in lists too right? Thanks for tips

  • hello world
    hello world年 前

    thanks python is cool you can sort any data structure based on the index

  • Mathi Yazhagan
    Mathi Yazhagan年 前

    Well explained. I am looking for this alsorted solution right now 👌👌

  • Amulya's Academy

    Amulya's Academy

    年 前

    Thank you :)

  • Ashwini Dhole
    Ashwini Dhole年 前

    How to sort without inbuilt functions

  • Ashwini Dhole

    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

    Amulya's Academy

    年 前

    You can use sorting algorithms. Bubble sort Merge sort ..... :)

  • SHUBHENDRA SINGH
    SHUBHENDRA SINGH年 前

    Awesome explanation..

  • Amulya's Academy

    Amulya's Academy

    年 前

    Thank you :)

  • Blatogh
    Blatogh年 前

    it is so clear OMG

  • Amulya's Academy

    Amulya's Academy

    年 前

    Thank you :)

  • Blatogh
    Blatogh年 前

    Actually, nice

  • Amulya's Academy

    Amulya's Academy

    年 前

    Thank you :)

  • Dmitry Shmakov
    Dmitry Shmakov年 前

    haha good job, I liked your explanations. Thank you for these tutorials!

  • dhanushka iroshan

    dhanushka iroshan

    3 个月 前

    Awesome explanation ☺️

  • Amulya's Academy

    Amulya's Academy

    年 前

    Pleasure :)

  • Somaye Madadpour
    Somaye Madadpour年 前

    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.

  • Unity affect
    Unity affect年 前

    thank you for you nice video

  • Tushar Goyal
    Tushar Goyal年 前

    Which mic do you use?

  • darlo LO
    darlo LO年 前

    why you ding it in shell, and how can you print it???

  • Colorful Codes
    Colorful Codes2 年 前

    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!

  • Es18cs38 Logesh k
    Es18cs38 Logesh k2 年 前

    Super explanation.

  • Amulya's Academy

    Amulya's Academy

    2 年 前

    Thank you :)

  • Atul
    Atul2 年 前

    Liked your videos a lot. Videos are very helpful for beginners.

  • Amulya's Academy

    Amulya's Academy

    2 年 前

    Thank you:)

  • SATYAM TRIPATHI
    SATYAM TRIPATHI2 年 前

    well explained...thanks

  • Amulya's Academy

    Amulya's Academy

    2 年 前

    Thank you:)

  • Vipin Mishra
    Vipin Mishra2 年 前

    Your voice is amazing and explanation also best

  • ROHIT kING

    ROHIT kING

    4 个月 前

    Flirt yaha pe bhi😜😂

  • Amulya's Academy

    Amulya's Academy

    2 年 前

    Thank you:)

  • innocent sahir
    innocent sahir2 年 前

    i have queries on python can u help me

  • innocent sahir

    innocent sahir

    2 年 前

    i have forwarded my query pls get to me asap

  • innocent sahir

    innocent sahir

    2 年 前

    waiting for your reply

  • Atif shaik

    Atif shaik

    2 年 前

    waiting to your reply pls contact me asap thanks

  • Atif shaik

    Atif shaik

    2 年 前

    Thanks

  • Amulya's Academy

    Amulya's Academy

    2 年 前

    amulsacademy@gmail.com

  • Atif Shaik
    Atif Shaik2 年 前

    can you help with Memory Game programs and remote server using python

  • vinod CH
    vinod CH2 年 前

    Waiting for some more videos and plz speak abut small project that will help lot of members

  • Amulya's Academy

    Amulya's Academy

    2 年 前

    Sure:)

  • TANMOY SARDAR
    TANMOY SARDAR2 年 前

    maam have u done with that turtle graphics part

  • TANMOY SARDAR

    TANMOY SARDAR

    2 年 前

    Amuls Academy mam then will u post plz maam its urgent coding samajna hain mereko

  • Amulya's Academy

    Amulya's Academy

    2 年 前

    No:(

  • Rishi Sharma
    Rishi Sharma2 年 前

    Mam will you teach Numpy, pandas, Matplotlib,scikit learn etc.. in the future videos😁

  • Rishi Sharma

    Rishi Sharma

    2 年 前

    Thanks mam

  • Amulya's Academy

    Amulya's Academy

    2 年 前

    Sure:)

  • charan charan
    charan charan2 年 前

    If I post any queries in python then will you respond with answer

  • ThatControlUser WhoSucksAtPvP

    ThatControlUser WhoSucksAtPvP

    2 天 前

    @kurakula prashanth kwargs :/

  • kurakula prashanth

    kurakula prashanth

    年 前

    @Amulya's Academy you didn't passed the arguments to the function but you got the output how?

  • kurakula prashanth

    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

    Amulya's Academy

    2 年 前

    yes:)

  • Amulya's Academy

    Amulya's Academy

    2 年 前

    yes:)

下一个