[BangPypers] List compression improvement

vijay vnbang2003 at yahoo.com
Wed Jan 9 08:50:13 CET 2013


Corrected subject spell 


________________________________
 From: vijay <vnbang2003 at yahoo.com>
To: Bangalore Python Users Group - India <bangpypers at python.org> 
Sent: Wednesday, 9 January 2013 1:11 PM
Subject: [BangPypers] List compression imrpovement
 
Hi,
   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
Vijay
_______________________________________________
BangPypers mailing list
BangPypers at python.org
http://mail.python.org/mailman/listinfo/bangpypers


More information about the BangPypers mailing list