(key_dict, *args)
Quick way of recording keypresses that doesn't involve a million try/excepts.
Quick way of recording keypresses that doesn't involve a million try/excepts.
Quick way of recording keypresses that doesn t involve a million try / excepts .
def _record_keypress(key_dict, *args):
    """Quick way of recording keypresses that doesn't involve a million try/excepts."""

    everything = key_dict['All']
    session = key_dict['Session']
    
    for i in args[:-1]:
        try:
            everything[i]
        except KeyError:
            everything[i] = {}
        everything = everything[i]
        try:
            session[i]
        except KeyError:
            session[i] = {}
        session = session[i]
    
    try:
        everything[args[-1]] += 1
    except KeyError:
        everything[args[-1]] = 1
    try:
        session[args[-1]] += 1
    except KeyError:
        session[args[-1]] = 1
def _record_keypress ( key_dict , * args ) : everything = key_dict [ 'All' ] session = key_dict [ 'Session' ] for i in args [ : - 1 ] : try : everything [ i ] except KeyError : everything [ i ] = { } everything = everything [ i ] try : session [ i ] except KeyError : session [ i ] = { } session = session [ i ] try : everything [ args [ - 1 ] ] += 1 except KeyError : everything [ args [ - 1 ] ] = 1 try : session [ args [ - 1 ] ] += 1 except KeyError : session [ args [ - 1 ] ] = 1