我有很多看起来像的列表
['it']
['was']
['annoying']
Run Code Online (Sandbox Code Playgroud)
我希望以上看起来像
['it', 'was', 'annoying']
Run Code Online (Sandbox Code Playgroud)
我如何实现这一目标?
我有两个列表需要组合,其中第二个列表忽略第一个列表的任何重复...有点难以解释,所以让我展示一下代码的样子,以及我想要的结果.
first_list = [1, 2, 2, 5]
second_list = [2, 5, 7, 9]
# The result of combining the two lists should result in this list:
resulting_list = [1, 2, 2, 5, 7, 9]
Run Code Online (Sandbox Code Playgroud)
您会注意到结果具有第一个列表,包括其两个"2"值,但second_list还具有额外的2和5值的事实未添加到第一个列表中.
通常对于这样的事情,我会使用集合,但first_list上的一个集合将清除它已有的重复值.所以我只想知道实现这种理想组合的最佳/最快方法.
谢谢.