Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with comparing list
#1
I want to compare the elements of two list and the code to return True if all of the elements in the second list is present in the first. The code is:
list_a = [25,15,40,40,10]
list_b = [40,40,10]

if all(i for i in list_b) in list_a:
    print('true')
else:
    print('false')
When run, the code returns False despite all of the elements in list_b being present in list_a.

Would appreciate some help here.

Thanks
Reply


Messages In This Thread
Problem with comparing list - by palladium - Jul-08-2020, 07:38 AM
RE: Problem with comparing list - by ndc85430 - Jul-08-2020, 07:53 AM
RE: Problem with comparing list - by DeaD_EyE - Jul-08-2020, 10:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Comparing List values to get indexes Edward_ 7 1,253 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  Problem with "Number List" problem on HackerRank Pnerd 5 2,168 Apr-12-2022, 12:25 AM
Last Post: Pnerd
  comparing 2 dimensional list glennford49 10 4,238 Mar-24-2020, 05:23 PM
Last Post: saikiran
  Looping through dictionary and comparing values with elements of a separate list. Mr_Keystrokes 5 3,968 Jun-22-2018, 03:08 PM
Last Post: wavic
  Get the correct value when comparing with the list chris0147 8 4,882 Aug-09-2017, 01:21 AM
Last Post: chris0147
  Create a new list by comparing values in a list and string DBS 2 3,575 Jan-14-2017, 07:59 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020