<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def expand_dir(_dir, cwd=os.getcwd()):
 """Return path with environmental variables and tilde ~ expanded. :param _dir: :type _dir: str :param cwd: current working dir (for deciphering relative _dir paths) :type cwd: str :rtype; str """

    _dir = os.path.expanduser(os.path.expandvars(_dir))
    if not os.path.isabs(_dir):
        _dir = os.path.normpath(os.path.join(cwd, _dir))
    return _dir