Reputation: 6197
Say that I have a set of strings. Is it possible to search using a partial string, and if any of the values in the set contain that partial string, return the full string?
example:
thisSet = { 'orange', 'orabolo', 'apple', 'dog'}
partialString = 'ora'
setFunction(thisSet, partialString)
> 'orange', 'orabolo'
Upvotes: 1
Views: 1660
Reputation: 19264
Use a simple set comprehension:
{i for i in thisSet if partialString in i}
>>> thisSet = {'orange', 'orabolo', 'apple', 'dog'}
>>> partialString = 'ora'
>>> {i for i in thisSet if partialString in i}
{'orange', 'orabolo'}
>>>
Upvotes: 3