我有一个列表['4H', '5D', 'AC', '7H']
和[H, D]
. 如何在跳过所有以“A”开头的元素的同时检查所有元素的第一个索引 [1] 是否在第二个列表中。
对于python 3.9+(startswith()
方法):
lst1 = ['4H', '5D', 'AC', '7H', '7J']
lst2 = ['H', 'D']
for item in lst1:
if not item.startswith('A') and item[1] in lst2:
print(item)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句