credit:http://stackoverflow.com/a/62680
class Foo(object):
#...
这样的建立方式,可以是Foo类自带__dict__
,其中包含了所有类成员的字典,因此可以使用下面的语句:
pack_info = dict((key, p.__dict__[key]) for key in Package.json_members)
实现字典的部分拷贝
>> mydict = {'foo': 'foo', 'bar': 'bar', 'hi':'hi'}
>> set(['foo', 'bar']) <= set(mydict)
True
result = sorted(memory_dict, key=lambda elem: elem[0]+elem[1], reverse=True)
link: http://docs.python.org/2/tutorial/controlflow.html#lambda-expressions