Skip to content

Tag: contains

Is there a short contains function for lists?

Given a list xs and a value item, how can I check whether xs contains item (i.e., if any of the elements of xs is equal to item)? Is there something like xs.contains(item)? For performance considerations, see Fastest way to check if a value exists in a list. Answer Use: Also, inverse operation: It works fine …

Check if multiple strings exist in another string

How can I check if any of the strings in an array exists in another string? For example: How can I replace the if a in s: line to get the appropriate result? Answer You can use any: Similarly to check if all the strings from the list are found, use all instead of any.