def make_key(*args, **kwargs):
sep = kwargs.get('<STR_LIT>', u"<STR_LIT:_>")<EOL>exclude_last_string = kwargs.get('<STR_LIT>', False)<EOL>string_array = []<EOL>for arg in args:<EOL><INDENT>if isinstance(arg, list):<EOL><INDENT>string_array.append(six.text_type(sep.join(arg)))<EOL><DEDENT>else:<EOL><INDENT>if exclude_last_string:<EOL><INDENT>new_key_array = arg.split(sep)[:-<NUM_LIT:1>]<EOL>if len(new_key_array) > <NUM_LIT:0>:<EOL><INDENT>string_array.append(make_key(new_key_array))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>string_array.append(six.text_type(arg))<EOL><DEDENT><DEDENT><DEDENT>return sep.join(string_array)<EOL>
Given any number of lists and strings will join them in order as one
string separated by the sep kwarg.  sep defaults to u"_".

Add exclude_last_string=True as a kwarg to exclude the last item in a
given string after being split by sep.  Note if you only have one word
in your string you can end up getting an empty string.

Example uses:

>>> from mongonaut.forms.form_utils import make_key
>>> make_key('hi', 'my', 'firend')
>>> u'hi_my_firend'

>>> make_key('hi', 'my', 'firend', sep='i')
>>> 'hiimyifirend'

>>> make_key('hi', 'my', 'firend',['this', 'be', 'what'], sep='i')
>>> 'hiimyifirendithisibeiwhat'

>>> make_key('hi', 'my', 'firend',['this', 'be', 'what'])
>>> u'hi_my_firend_this_be_what'