<div dir="ltr">On 5 July 2013 10:28, Haoyi Li <span dir="ltr"><<a href="mailto:haoyi.sg@gmail.com" target="_blank">haoyi.sg@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">Is there a better way to flatten lists than [item for sublist in l for item in sublist]? I naturally don't use sum() for much, but if i could, sum(my_list) looks much better than [item for sublist in my_list for item in sublist]. Looking at <a href="http://stackoverflow.com/questions/952914/making-a-flat-list-out-of-list-of-lists-in-python" target="_blank">http://stackoverflow.com/questions/952914/making-a-flat-list-out-of-list-of-lists-in-python</a>, all the alternatives seem equally obtuse and verbose. I have a lot of list flattenings I would love to use sum(my_list) for if I had the chance.</div>
</blockquote><div><br></div><div style>Only partially facetious, but</div><div style><br></div><div style>newlist = flatten(list_of_lists)</div><div style><br></div><div style>In other words, if you don't like the nested comprehension, hide it in a personal function. No need to force the functionality into an existing builtin,</div>
<div style><br></div><div style>Not-every-one-liner-needs-to-be-a-builtin-ly y'rs,</div><div style>Paul<br></div></div><br></div></div>