2013-11-01 161 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很高興幫助。 :-) –

相關問題