Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with comparing list
#2
The all function doesn't work like that - it returns True if all the values are truthy, which for integers means non-zero. So, your call to all returns True and the value True is not in list_a, so execution enters the else branch.

Probably the most natural way to do what you want is to turn the lists into sets and use one of the set operations (see, e.g. docs).
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,368 Jun-09-2023, 04:57 PM
Last Post: deanhystad
  Problem with "Number List" problem on HackerRank Pnerd 5 2,222 Apr-12-2022, 12:25 AM
Last Post: Pnerd
  comparing 2 dimensional list glennford49 10 4,291 Mar-24-2020, 05:23 PM
Last Post: saikiran
  Looping through dictionary and comparing values with elements of a separate list. Mr_Keystrokes 5 4,016 Jun-22-2018, 03:08 PM
Last Post: wavic
  Get the correct value when comparing with the list chris0147 8 4,926 Aug-09-2017, 01:21 AM
Last Post: chris0147
  Create a new list by comparing values in a list and string DBS 2 3,620 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