You can use sets

On Tue, Jan 25, 2022 at 7:47 AM bnmng <[email protected]> wrote:

> Hello,
>
> Is there a built in function that compares two or more lists and returns
> elements common to all?
>
> like this:
>
> def in_both( list_a, list_b ):
> list_c=[]
> for value in list_a:
> if value in list_b:
> list_c.append(value)
> return list_c
>
> Or this:
> def in_all(list_of_lists):
> list_a = list_of_lists.pop(0)
> list_b = []
> for value in list_a:
> in_all_lists = True
> for each_list in list_of_lists:
> if not value in each_list:
> in_all_lists = False
> if in_all_lists:
> list_b.append(value)
> return list_b
>
> Thank you
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/bf2cf505-6205-4fcf-affd-9a0a2f7e5e00n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/bf2cf505-6205-4fcf-affd-9a0a2f7e5e00n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
-- 
Oussama Chafiqui

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPvcp%2BUcudpPQygoTNUrSYhdmLWFeMH%2BGO7ERuXGH5JNhcVQXg%40mail.gmail.com.

Reply via email to