Help with this code

Joel Goldstick joel.goldstick at gmail.com
Mon Jan 9 13:43:35 EST 2017


On Mon, Jan 9, 2017 at 1:02 PM, Gilmeh Serda
<gilmeh.serdah at nothing.here.invalid> wrote:
> On Mon, 09 Jan 2017 05:08:51 -0800, José Manuel Suárez Sierra wrote:
>
>> elements. For example, if we have a list_a=["a","b","c","d"] and
>> list_b=["a","b"] I want to obtain a new list_c containing elements that
>> match between these lists (a and b here),
>
> Perhaps this might work:
>
>>>> list(set(list_a).intersection(set(list_b)))
> ['a', 'b']
>
> HTH
> --
> Gilmeh
> --
> https://mail.python.org/mailman/listinfo/python-list

I was confused whether the OP wanted to retain the list order.  The
spec seemed unclear. If not, this is a nice approach.  Of course this
also removes duplicate values.

-- 
Joel Goldstick
http://joelgoldstick.com/blog
http://cc-baseballstats.info/stats/birthdays



More information about the Python-list mailing list