def example_1():
    rows = [
        {'fname': 'Brian', 'lname': 'Jones', 'uid': 1003},
        {'fname': 'David', 'lname': 'Beazely', 'uid': 1002},
        {'fname': 'John', 'lname': 'Cleese', 'uid': 1001},
        {'fname': 'Big', 'lname': 'Jones', 'uid': 1004}
    ]

    from operator import itemgetter
    rows_by_fname = sorted(rows, key = itemgetter('fname'))
    rows_by_uid = sorted(rows, key = itemgetter('uid'))
    print(rows_by_fname)
    print(rows_by_uid)

    row_by_lfname = sorted(rows , key = itemgetter('lname', 'fname'))
    print(row_by_lfname)

    rows_by_fname = sorted(rows, key = lambda r: r['fname'])
    rows_by_lfname = sorted(rows, key = lambda r: (r['fname'], r['lname']))

    print(min(rows, key = itemgetter('uid')))
    print(max(rows, key=itemgetter('uid')))


if __name__ == '__main__':
    example_1()

def example_1():
    rows = [
        {'fname': 'Brian', 'lname': 'Jones', 'uid': 1003},
        {'fname': 'David', 'lname': 'Beazely', 'uid': 1002},
        {'fname': 'John', 'lname': 'Cleese', 'uid': 1001},
        {'fname': 'Big', 'lname': 'Jones', 'uid': 1004}
    ]

    from operator import itemgetter
    rows_by_fname = sorted(rows, key = itemgetter('fname'))
    rows_by_uid = sorted(rows, key = itemgetter('uid'))
    print(rows_by_fname)
    print(rows_by_uid)

    row_by_lfname = sorted(rows , key = itemgetter('lname', 'fname'))
    print(row_by_lfname)

    rows_by_fname = sorted(rows, key = lambda r: r['fname'])
    rows_by_lfname = sorted(rows, key = lambda r: (r['fname'], r['lname']))

    print(min(rows, key = itemgetter('uid')))
    print(max(rows, key=itemgetter('uid')))


if __name__ == '__main__':
    example_1()
