Python: Is it possible to skip values in tuple assignment?
<p>I have a function which splits string in two parts at first encountered colon (skipping parts enclosed in brackets). This function returns tuple of three elements: index where the colon was encountered, part before colon and part after colon:</p>

<pre><code>def split_on_colon(str):
    colon_ptr = find_separator(str, 0, ':')
    if colon_ptr == -1:
        return (colon_ptr, str, None)
    return (colon_ptr, str[:colon_ptr], str[colon_ptr+1:])
</code></pre>

<p>I call it this way:</p>

<pre><code>def substitute_expression(expression):
    # Split function and arguments
    colon_ptr, func, args = split_on_colon(expression)
    ...
</code></pre>

<p>But sometimes it don't care about <code>colon_ptr</code> part.</p>

<p>Is there any simple construction in Python that would allow throwing away part of tuple in assignment, so that it wouldn't waste memory and variables namespace?</p>

<p>Something like this:</p>

<pre><code>Ignore, func, args = split
</code></pre>

<p>The best way for refusing of consuming extra memory is to handle this within your function. You can use a flag as an argument for your function then based on this flag you can decide to return 2 or 3 items.</p>

<pre><code>def split_on_colon(my_str, flag):
    colon_ptr = find_separator(my_str, 0, ':')
    if flag:
        if colon_ptr == -1:
            return (my_str, None)
        return (my_str[:colon_ptr], my_str[colon_ptr+1:])
    else:
        if colon_ptr == -1:
            return (colon_ptr, my_str, None)
        return (colon_ptr, my_str[:colon_ptr], my_str[colon_ptr+1:])
</code></pre>

python