0

I have two lists, englishclub and listofallclub

I have already checked that not all elements in englishclub are in listofallclub, but I want to find which element is missing from listofallclub

I expect the lists to be very large.

listallclub = df.Club.tolist()

result =  all(elem in englishclub  for elem in  listallclub)

if result:
    print("Yes, englishclub  contains all elements in listallclub")    
else :
    print("No, englishclub  does not contains all elements in listallclub")

I would like my outputto be the list of elements that are in englishclub but not in listofallclub

Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96
wildan
  • 1
  • 1

2 Answers2

0

other_clubs = [e for e in listallclub if e not in englishclub]

kszl
  • 1,203
  • 1
  • 11
  • 18
  • Hi! While this may be an answer to the question (untested), code only answers are discouraged on SO. Please consider adding an explanation to your answer to help OP better understand, and to provide greater benefit to future visitors of the site. Thanks! – d_kennetz Mar 25 '19 at 14:53
0

You can use list comprehension,

e = [ec for ec in englishclub if ec not in listallclub]

if e:
    print("No, englishclub  does not contains all elements in listallclub")
    print("And they are")
    print(e)
else :
    print("Yes, englishclub  contains all elements in listallclub")    
marmeladze
  • 6,468
  • 3
  • 24
  • 45