Menu

gitpiper

some python Code Snippet in 2024

listintermediate

Last Updated: 22 April 2024

Checks if the provided function returns True for at least one element in the list.

  • Use any() in combination with map() to check if fn returns True for any element in the list.
def some(lst, fn = lambda x: x): return any(map(fn, lst))
some([0, 1, 2, 0], lambda x: x >= 2 ) # True some([0, 0, 1, 0]) # True

python snippet similar to some 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! ✌️