【发布时间】:2020-09-08 18:14:41
【问题描述】:
我有一个 Python 列表:
test_list = ['LeBron James', 'and', 'Nina Mata', 'Dan Brown', 'Derrick Barnes', 'and',
'Gordon C. James', 'J. Kenji López-Alt', 'and', 'Gianna Ruggiero', ]
我想要这样的输出:
final_list = ['LeBron James and Nina Mata', 'Dan Brown', 'Derrick Barnes and
Gordon C. James', 'J. Kenji López-Alt and Gianna Ruggiero']
简而言之,我希望将一项 before '和'一项 after 'and' 组合起来。另一方面,没有 'and' 的名称不应组合并保持原样。我们如何在 Python 中做到这一点?
【问题讨论】:
-
你能有多个“和”组吗? (喜欢
["A", "and", "B", "and", "C"])
标签: arrays python-3.x string