[BangPypers] List compression imrpovement
jeffjosejeff at gmail.com
Wed Jan 9 09:13:33 CET 2013
Your #2 isnt a *one-line solution. *Its multple statements joined as one.
If that works, here's an improvement.
>>> tuple(x for x in a if not x%2), tuple(x for x in a if not x%3)
((4, 12), (9, 12, 15, 21))
On Wed, Jan 9, 2013 at 1:11 PM, vijay <vnbang2003 at yahoo.com> wrote:
> I want to know if there is any other better way for improving below
> list compression. I have to use list compression only to achieve it.
> say i have list a=[1, 4, 9, 12, 15, 21] expected result (4, 12), (9,
> 12, 15, 21)
> few solutions are
> 1) [filter(None, l) for l in zip(*[(x if x % 2 == 0 else None, x if x %
> 3 == 0 else None) for x in a])]
> 2) [y for y in a if bool(y%2==0)],[y for y in a if bool(y%3==0)]
> Any other better way to improve this.
> With Thanks
> BangPypers mailing list
> BangPypers at python.org
More information about the BangPypers