2013-11-01 110 views

回答

10

使用reduceoperator.getitem的方式。

演示:

>>> from operator import getitem 
>>> d = {'a': {'b': {'c': 100}}} 
>>> reduce(getitem, ['a', 'b', 'c'], d) 
100 
>>> d['a']['b']['c'] 
100 
+0

尼斯。我想我需要getitem之类的东西,甚至不知道getitem是否存在。谢谢! –

+0

@DustinWyatt很高兴帮助。 :-) –

相关问题