我们说我有一个像(20140101224466, 20140209226655, ...)
这样的值的集合,
我有一个包含('abcde.test.20140101224466', rbtd.test.20140209226655)
的列表。
如何将我的列表与集合进行比较,以仅获取列表中包含集合中值的值?有更优雅的方法吗?
答案 0 :(得分:1)
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]
答案 1 :(得分:0)
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']