Menu

gitpiper

similarity python Code Snippet in 2023

listbeginner

Last Updated: 28 January 2023

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 January 2023

Subscribe to our Newsletter

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

© 2023 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! ✌️