18 thoughts on “Python Programming Tutorial – 38 – Unpack List or Tuples

  1. Viet Huynh

    Like these videos a lot.

    Here is some thing fun that I learn so far

    import operator
    # this function will sort the grade and we will calculate the average of
    # 1) two lowest grade
    # 2) remainder grade
    # if average two lowest grade > 50 and average remainder > 70 -> Passed, otherwise failed
    def validate_performance(student):
    StudentName = list(student.keys())[0]
    StudentGrade = student[StudentName]

    LowestGrade1,LowestGrade2,*TopGrade = StudentGrade
    Avg_LowestGrade = (LowestGrade1+LowestGrade2)/2
    Avg_TopGrade = sum(TopGrade)/len(TopGrade)

    print(StudentName,"| Avg Lowest Grade:",Avg_LowestGrade,"| Avg Top Grade:",Avg_TopGrade,"| Final Result","Passed" if Avg_TopGrade>=70 and Avg_LowestGrade>=50 else "Failed")

    Student_Grade = {'Brian':[55,60,50,70,90,75,85,100],'Albert':[50,45,90,80,55,95],'Cindy':[60,55,70,60,55,75,80,50,50,60]}
    for key,value in sorted(Student_Grade.items(),key=operator.itemgetter(0)):


    Albert | Avg Lowest Grade: 47.5 | Avg Top Grade: 80.0 | Final Result Failed
    Brian | Avg Lowest Grade: 52.5 | Avg Top Grade: 80.0 | Final Result Passed
    Cindy | Avg Lowest Grade: 50.0 | Avg Top Grade: 64.375 | Final Result Failed

  2. Ayy Lmao

    If any of you are wondering what is the difference between lists and tuples it's pretty simple.
    After creating a list everyone knows we can append more elements to it (or delete, or insert …) in general we can edit that list.
    But after creating a tuple, we cannot edit the content of that tuple it's basically immutable.
    Oh and yeah also tuples use classic parenthesis instead of brackets.

  3. 李圖次

    Bucky, you missed on how to unpack tuples, although the same methodology, tuple has no .sort() method. The sorted() function is better.

  4. Kuldeep Sharma

    what if we want to Do other Mathematical things with Part of list like subtraction, multiplication, division and other How we supposed to Do that….subtact(middle) isn't working

  5. DavidAnatolie

    hey guys I realized that the asterisk (*) can move around to the first variable or even the last variable.

    e.g. first, second, *rest = <list>
    *beg, second_last, last = <list>

    pretty cool observation, eh?

  6. Warren Crasta

    Note: We can also use def drop_first_last(*grades) and pass in a variable number of arguments, such as drop_first_last(10,5,10,3), instead of a list. We learned this in a previous video and it does the same thing.

  7. Belouz Tarek

    thank you for the course.please how to calculate the number of tags in an HTML,like (<head>,</head>,<html>,</html>,<body>,</body>….etc)

  8. Mohammad Mahjoub

    Simple question: Why can't we do this:
    def drop_fist_last(marks):
    marks = first, *middle, last
    ave_marks = sum(marks)/ len(marks)
    drop_fist_last([94, 34, 32, 44, 22, 99])
    drop_fist_last([94, 34, 32, 44, 22, 99, 88, 44, 22])

Leave a Reply