Why does list have no 'get' method?
stefan_ml at behnel.de
Thu Feb 7 11:42:46 CET 2008
Denis Bilenko wrote:
> Raymond Hettinger wrote:
>> If positions 0 and 1 are optional, how do you expect to know whether
>> "path" is going to be at position 2? This problem doesn't exist with
>> dictionaries because the presence or absence of optional entries does
>> not affect the key reference to other entries. Accordingly, I
>> wouldn't expect that dict.get() would have a parallel list.get() with
>> plausible use cases.
> If you want to fill position 2, then positions 0 and 1 are mandatory.
> It is the simplest possible option parsing, I didn't said it was the
> most flexible :)
d = dict(enumerate(args))
print d, d, d.get(2)
More information about the Python-list