06.0 Python‎ > ‎Python Notes‎ > ‎List Processing‎ > ‎

.sort() and sorted()

.sort()

sorts and changes the original list

Syntax

    list.sort(key=str.lower)

key=str.lower will ignore the case of word and is optional

Example

    data.sort(key=str.lower)

sorted()

returns a sorted list; the original list remains unchanged

Syntax

    sorted_list = sorted(unsorted_list, key=str.lower)

Example

    data = sorted(data, key=str.lower)

Comments