Q:

How to iterate through list and populated nested dictionary Python?

I am attempting to create a nested dictionary, and want to populate it with arguments passed to my Python script from the command line. I want each entry in the command line to be a key in the dictionary, and the dictionary will terminate with the value of the last command line argument. The 'root' key in the dictionary will be the 2nd argument passed to the command line (in index 0, the root key would be sys.argv[1]). I am looking for something like this:
./script.py arg1 arg2 arg3 arg4 arg5

resulting in the dictionary:
{arg1: {arg2: {arg3: {arg4: arg5}}}}

Here's what I have so far:
parameter = {}
parameter[sys.argv[-2]] = sys.argv[-1]
for i in reversed(sys.argv[1:-2]):
    print(parameter)
    parameter[i] = parameter

which results in the output: 
{'arg2': {...}, 'arg1': {...}, 'arg3': {...}, 'arg4': 'arg5'}

A:

I would do this with recursion. An easy example would be:
import sys

def create_dict(items):
    if len(items) == 1:
        return items[0]
    else:
        return {items[0]: create_dict(items[1:])}

if __name__ == '__main__':
    result = create_dict(sys.argv[1:])
    print(result)

