Menu

gitpiper

is_contained_in python Code Snippet in 2024

listintermediate

Last Updated: 13 April 2024

Checks if the elements of the first list are contained in the second one regardless of order.

  • Use count() to check if any value in a has more occurrences than it has in b.
  • Return False if any such value is found, True otherwise.
def is_contained_in(a, b): for v in set(a): if a.count(v) > b.count(v): return False return True
is_contained_in([1, 4], [2, 4, 1]) # True

python snippet similar to is_contained_in For You in April 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️