我有两个名称(字符串)列表,如下所示:
executives = ['Brian Olsavsky', 'Some Guy', 'Some Lady']
analysts = ['Justin Post', 'Some Dude', 'Some Chick']
我需要找到这些名称出现在如下所示的字符串列表中的位置:
str = ['Justin Post - Bank of America',
"Great. Thank you for taking my question. I guess the big one is the deceleration in unit growth or online stores.",
"I know it's a tough 3Q comp, but could you comment a little bit about that?",
'Brian Olsavsky - Amazon.com',
"Thank you, Justin. Yeah, let me just remind you a couple of things from last year.",
"We had two reactions on our Super Saver Shipping threshold in the first half." ,
"I'll just remind you that the units those do not count",
"In-stock is very strong, especially as we head into the holiday period.",
'Dave Fildes - Amazon.com',
"And, Justin, this is Dave. Just to add on to that. You mentioned the online stores.
我需要这样做的原因是这样我可以将对话字符串连接在一起(由名称分隔)。我该如何有效地做到这一点?
我查看了一些类似的问题并尝试了无济于事的解决方案,例如:
if any(x in str for x in executives):
print('yes')
和这个 ...
match = next((x for x in executives if x in str), False)
match