Menu

gitpiper

similarity python Code Snippet in 2024

listbeginner

Last Updated: 28 October 2024

Returns a list of elements that exist in both lists.

  • Use a list comprehension on a to only keep values contained in both lists.
def similarity(a, b): return [item for item in a if item in b]
similarity([1, 2, 3], [1, 2, 4]) # [1, 2]

python snippet similar to similarity For You in October 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! ✌️