'Any good reason my company's non-looping code does dict(enumerate(list)).get(number) instead of just list[number]?

There's a legacy piece of Python code at my company that I'm considering refactoring.

Instead of just accessing sys.argv[0] and sys.argv[3] and such, it first does args_dict = dict(enumerate(sys.argv)) and then accesses system parameters as args_dict.get(0) and args_dict.get(3).

This seems silly to me.

I'm wondering if it's a typo left over from some sort of refactor away from a more complicated thing that I can now also refactor away.

I noticed that some of the more complex codebases using this pattern do pass args_dict to methods as a parameter named args_dict ... but it seems like sys.argv could just as easily be passed as args_list or even just called directly from those methods?

Is there any possible reason, such as safety when using an out-of-bounds argument place number, that it's actually preferable to access things with a dict as .get(number) rather than with a list as [number]? Or can I safely refactor for simplicity?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source