Sort Tuples by First Element

  • Share this:

Code introduction


This function takes a list of tuples as an argument, sorts the list based on the first element of each tuple, and returns the sorted list.


Technology Stack : Sorting

Code Type : Function

Code Difficulty : Beginner


                
                    
def aordnly(arg1, arg2):
    """
    排序一个元组列表,并返回排序后的列表,只对元组的第一个元素进行排序。
    """
    return sorted(arg1, key=lambda x: x[0])                
              
Tags: