Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Sorting a list using a named function

ex_lst = ['hi', 'how are you', 'bye', 'apple', 'zebra', 'dance']

def second_let(x):

    lst= []
    for wrd in x:
        lst.append(wrd[1])
    return lst

print(second_let(ex_lst))
print(sorted(second_let(ex_lst)))

sorted_by_second_let= sorted(ex_lst, key= second_let)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Sorting #list #named #function
ADD COMMENT
Topic
Name
9+8 =