<div dir="ltr"><div><div><div class="gmail_extra"><div class="gmail_quote">On Thu, Apr 7, 2016 at 1:03 PM, Michel Desmoulin <span dir="ltr"><<a href="mailto:desmoulinmichel@gmail.com" target="_blank">desmoulinmichel@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Python is a lot about iteration, and I often have to get values from an<br>
iterable. For this, unpacking is fantastic:<br>
<br>
a, b, c = iterable<br>
<br>
One that problem arises is that you don't know when iterable will<br>
contain 3 items.<br>
<br>
In that case, this beautiful code becomes:<br>
<br>
iterator = iter(iterable)<br>
a = next(iterator, "default value")<br>
b = next(iterator, "default value")<br>
c = next(iterator, "default value")<br></blockquote></div><br></div><div class="gmail_extra">I think rather than adding a new syntax, it would be better to just make one of these work:<br><br></div>a, b, c, *d = itertools.chain(iterable, itertools.repeat('default value'))<br></div><br>a, b, c = itertools.chain(iterable, itertools.repeat('default value'))<br><br>a, b, c = itertools.chain.from_iterable(iterable, default='default value')<br><br></div></div>