Reputation: 1
Let's say I have a set with values like (20140101224466, 20140209226655, ...)
,
and I have a list that contains ('abcde.test.20140101224466', rbtd.test.20140209226655)
.
How would I compare my list against the set to get only the values in the list that contain the values in the set? Is there a more elegant approach?
Upvotes: 0
Views: 65
Reputation: 6238
set1 = {20140101224466, 20140209226655}
list2 = ['abcde.test.20140101224466', 'rbtd.test.20140209226655']
print [i for i in list2 if int(i.split('.')[-1]) in set1]
# ['rbtd.test.20140209226655', 'abcde.test.20140101224466']
Upvotes: 0
Reputation: 7203
test_set = {20140101224466, 20140209226655, ... }
test_list = ['abcde.test.20140101224466', 'rbtd.test.20140209226655']
solution = [value for value in test_list if int(value.split('.')[-1]) in test_set]
Upvotes: 1