@andymitchhank/

itemattrgetter

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from operator import attrgetter, itemgetter

def itemattrgetter(item, attr):
    def inner(obj):
        retrieved_item = itemgetter(item)(obj)
        return attrgetter(attr)(retrieved_item)
    return inner

class Example(object):

    def __init__(self, test):
        self.test = test


x = Example(123)
y = Example(555)

l = [(1, x), (2, y)]

print(max(l, key=itemattrgetter(1, 'test')))