Sorting and Filtering Alphabetic Items from a List

  • Share this:

Code introduction


This function takes a list containing letters and numbers, and returns a sorted list containing only the letters.


Technology Stack : List comprehension, isalpha() method, sorted() function

Code Type : Function

Code Difficulty : Intermediate


                
                    
def aord_list(items):
    """
    排序并返回列表中的字母元素。

    :param items: 包含字母和数字的列表。
    :return: 排序后的字母元素列表。
    """
    return sorted([item for item in items if item.isalpha()])