+ 1

Question about lists in python...

Hey there! I have a question for you... If I have 2 lists... Example: A = [1,2,3,4,5,6] B = [1,4,9,16,25] how can I write a program that tells me in there is at least 1 element of A in B? Also another thing... If I have a lists of divisors of a number, how can I exclude 1 and the number itself from the list? Thank a lot to everyone!

4th Jun 2019, 11:06 AM
Andrea Scapin
Andrea Scapin - avatar
3 ответов
+ 5
Without using sets you can do that using loops. if any(i in B for i in A): print("The list B has atleast one item from the list A.")
4th Jun 2019, 11:41 AM
Seb TheS
Seb TheS - avatar
+ 2
Thanks to both of you!
4th Jun 2019, 11:43 AM
Andrea Scapin
Andrea Scapin - avatar