<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Nov 15, 2011, at 7:59 PM, Brian Rue wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">A variation on the same theme:<div><br></div><div><div>&gt;&gt;&gt; args = ["1", "2", "3,4", "5,6,7"]</div><div>&gt;&gt;&gt; args</div><div>['1', '2', '3,4', '5,6,7']</div>

<div>&gt;&gt;&gt; sum((x.split(',') for x in args), [])</div><div>['1', '2', '3', '4', '5', '6', '7']</div></div></blockquote><div><br></div><div>That's pretty clever, I never used sum that way, i.e. concatenating a string by using the list's + operator.</div><div><br></div><div>this is similar but without the "magic"</div><div><br></div><div>from&nbsp;itertools import chain</div><div>chain.from_iterable( x.split(',') for x in args)</div><div><br></div><div>Jason</div><br><blockquote type="cite"><div><div class="gmail_quote">On Tue, Nov 15, 2011 at 7:52 PM, Damon McCormick <span dir="ltr">&lt;<a href="mailto:damonmc@gmail.com">damonmc@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Casey,&nbsp;<div><br></div><div>What is the intent of the following line?</div><div><br></div><div><div class="im">&nbsp;&nbsp;x[i:i+1] = items<br>

<div><br></div></div><div>Namely, what is the purpose of blowing away item i of x every time you insert a new list of items into x?</div>
<div><br></div><div>Is it possible that you mean something more like the following?</div><div><br></div><div>&nbsp;&nbsp;x.extend(items)</div><div><br></div><div>If so, you could just do this:</div><div><br></div><div><div>&nbsp;&nbsp;for element in mylist:</div>


<div>&nbsp;&nbsp; &nbsp; &nbsp;items = element.split(',')</div><div>&nbsp;&nbsp; &nbsp; &nbsp;x.extend(items)</div></div><div><br></div><div>Or even this:</div><div><br></div><div><div>&nbsp;&nbsp;x = [item for element in mylist for item in element.split(,)]</div>


</div><div><br></div><font color="#888888"><div>-Damon</div></font><div><div></div><div class="h5"><div><br><br><div class="gmail_quote">On Tue, Nov 15, 2011 at 7:35 PM, Casey Callendrello <span dir="ltr">&lt;<a href="mailto:c1@caseyc.net" target="_blank">c1@caseyc.net</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Howdy there,<br>
Another python puzzle for everyone. I've been trying to come up with a Pythonic (i.e. no index variable) way of solving this.<br>
<br>
I have a list consisting of one or more independent arguments to a specific command-line option. Think ./foo.py -a 1 -a 15 -a 1203. Argparse handles this fine. However, a few of my users prefer to specify arguments separated by commas instead. This is a fairly reasonable on their part, as about half of the tools we use like it one way, and half prefer the other. I don't mind supporting both, and the input data can never have a comma otherwise.<br>



<br>
So, is there another way to express this code? In reality, the number of arguments is very small, so duplicating the array is no big deal. I'm still interested in a cleaner solution :-)<br>
<br>
i = 0<br>
while i &lt; len(mylist):<br>
 &nbsp; &nbsp;items = mylist[i].split(',')<br>
 &nbsp; &nbsp;if len(items) &gt; 1:<br>
 &nbsp; &nbsp; &nbsp; &nbsp;x[i:i+1] = items<br>
 &nbsp; &nbsp;i++<br>
<br>
--Casey Callendrello<br>
<br>
______________________________<u></u>_________________<br>
Baypiggies mailing list<br>
<a href="mailto:Baypiggies@python.org" target="_blank">Baypiggies@python.org</a><br>
To change your subscription options or unsubscribe:<br>
<a href="http://mail.python.org/mailman/listinfo/baypiggies" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/baypiggies</a><br>
</blockquote></div><br></div></div></div></div>
<br>_______________________________________________<br>
Baypiggies mailing list<br>
<a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a><br>
To change your subscription options or unsubscribe:<br>
<a href="http://mail.python.org/mailman/listinfo/baypiggies" target="_blank">http://mail.python.org/mailman/listinfo/baypiggies</a><br></blockquote></div><br></div>
_______________________________________________<br>Baypiggies mailing list<br><a href="mailto:Baypiggies@python.org">Baypiggies@python.org</a><br>To change your subscription options or unsubscribe:<br>http://mail.python.org/mailman/listinfo/baypiggies</blockquote></div><br></body></html>