[BangPypers] need help w.r.t itertools

Dhananjay Nene dhananjay.nene at gmail.com
Mon Sep 16 09:19:53 CEST 2013


On Mon, Sep 16, 2013 at 12:27 PM, Suyash Bhatt <bhatt.suyash at gmail.com> wrote:
> 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..*
> *
Python 2.7.3 (default, Apr 10 2013, 05:13:16)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import itertools
>>>
>>> a = ['my1','my2']
>>> b = ['name1', 'name2']
>>> c = ['my1', 'my2']
>>> e = ['my1name1my1','my1name2my1','foobar']
>>> d = [y for y in (''.join(x) for x in itertools.product(a, b, c)) if y in e]
>>>
>>> d
['my1name1my1', 'my1name2my1']
>>>


More information about the BangPypers mailing list