[BangPypers] need help w.r.t itertools
Suyash Bhatt
bhatt.suyash at gmail.com
Mon Sep 16 08:57:47 CEST 2013
thanks for the response..
what if i have another list
*e = [*'*my1name1is1','**my2name2is1','xyz','abc']*
*and in the list d, I want only the elements which are present in e..*
*
*
*in such a case,*
*d should have only 2 elements : ['**my1name1is1','**my2name2is1']*
*
*
i want the way with the least cyclomatic complexity to be able to do all
this!!
FYR :
*a=[‘my1’,’my2’]
*
**
*b=[‘name1’,’name2’]*
*c=[‘is1’]*
I want to iter through all and form another list with the following
appended strings:
*d=['my1name1is1','my1name2is1','my2name1is1','my2name2is1']*
Can this be done in a single line using the itertools module??
Regards,
Suyash
On Fri, Sep 13, 2013 at 6:09 PM, Saager Mhatre <saager.mhatre at gmail.com>wrote:
> On Fri, Sep 13, 2013 at 5:01 PM, Dhruv Baldawa <dhruvbaldawa at gmail.com
> >wrote:
>
> > d = [''.join(x) for x in itertools.product(a, b, c)]
> >
>
> Actually, using itertools.imap would ensure that the elements aren't
> computed till necessary. So...
>
> d = itertools.imap(''.join, itertools.product(a, b, c))
>
> - d
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> https://mail.python.org/mailman/listinfo/bangpypers
>
More information about the BangPypers
mailing list