<p dir="ltr">Just spend the extra two characters to do this with existing syntax: w('field1 field2 field3'). Implementation of the w() function is trivial.</p>
<div class="gmail_extra"><br><div class="gmail_quote">On Nov 12, 2016 9:04 AM, "Gary Godfrey" <<a href="mailto:g.pythonideas@wamp.us">g.pythonideas@wamp.us</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>I looked around for a while but didn't see this proposed anywhere. I apologize if I missed an existing discussion.</div><div><br></div><div>I do a fair amount of work with pandas and data munging. This means that I'm often doing things like:<br></div><div><br></div><div>mydf = df[ ['field1', 'field2', 'field3' ] ]</div><div><br></div><div>This is a little ugly, so if the list is long enough, I do:</div><div><br></div><div>mydf=df[ 'field1 field2 field3'.split() ]</div><div><br></div><div>This is a little more readable, but still a bit ugly. What I'm proposing here is:</div><div><br></div><div>mydf = df[ w'field1 field2 field3' ]</div><div><br></div><div>This would be identical in all ways (compile-time) to:</div><div><br></div><div>mydf = df[ ('field1', 'field2', 'field3') ]</div><div><br></div><div>This should work with all the python quote variations (w''', w""", etc). The only internal escapes are \\ indicating a \ and <backslash><space> indicating a non-splitting space:</div><div><br></div><div>songs = w'My\ Bloody\ Valentine Blue\ Suede\ Shoes'</div><div><br></div><div>One question is whether to have w'' be a list or a tuple. I leaned slightly towards tuple because it's faster on internal loops:</div><div><br></div><div><div>In [1]: %timeit a=('this','is','a','test')</div><div>100000000 loops, best of 3: 11.3 ns per loop</div></div><div><br></div><div><div>In [2]: %timeit a=['this','is','a','test']</div><div>10000000 loops, best of 3: 74.3 ns per loop</div></div><div><br></div><div>However, I mostly see lists used in the data science community, so it's a little less convenient:</div><div><br></div><div>other_fields = df.columns[-3:]</div><div>new_columns = w'field1 field2' + other_fields</div><div># ERROR - can't concatenate list to tuple</div><div>new_columns = list(w'field1 field2') + other_fields</div><div><br></div><div>I honestly could go either way with lists or tuples.</div><div><br></div><div>Other Languages:<br></div><div><br></div><div>perl has the qw operator:</div><div><br></div><div>@a = qw(field1 field2 field3);</div><div><br></div><div>ruby has %w</div><div><br></div><div>a=%w{field1 field2}<br></div><div><br></div><div>Thanks for reading this far :-)</div><div><br></div><div>Regards,</div><div>Gary Godfrey</div><div>Austin, TX</div><div><br></div><div><br></div><div><br></div></div>
<br>______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br></blockquote></div></div>