一次追加多个列表

时间:2018-08-26 01:54:09

标签: python list

将多个列表附加在一起的最Python方式和最快方式(可能是相同的)是什么?例如,给定以下列表:

a = [1, 2]
b = [3, 4]
c = [5, 6]
d = [7, 8]

我们得到一个列表:

combined = [1, 2, 3, 4, 5, 6, 7, 8]

3 个答案:

答案 0 :(得分:2)

在Python 3.5+中,您可以使用常规解压缩:

y

或者在Python 3.5+之前,您可以使用SELECT DISTINCTROW Query1.Period, Query1.Portfolio_1 FROM Query1 WHERE (((Query1.Period)="May 2018")) ORDER BY Query1.Portfolio_2, Query1.Department, Query1.Position_NO;

Private Sub newChangePeriodCriteria_Click()
Dim qdf As DAO.QueryDef
Dim qdfOLD As String
Set qdf = CurrentDb.QueryDefs("Query1_Mth")
With qdf
    qdf.SQL = sqlString

    .SQL = Replace(.SQL, "Period='May 2018'", "Period='Jun 2018'")
    ' Code to do stuff with SQL-string/query
   ' .SQL = qdfOLD ' Reset SQL to old setting
           qdfOLD = .SQL

     ' DoCmd.RunSQL (Replace("Period='May 2018'", "Period='Jun 2018'"))

End With
Set qdf = Nothing
End Sub

答案 1 :(得分:0)

我听不懂你 您是说如何合并它们? 例如

a = [1, 2]
b = [3, 4]
c = [5, 6]
d = [7, 8]
combined = a + b + c + d 

因此将合并为

[1, 2, 3, 4, 5, 6, 7, 8]

答案 2 :(得分:0)

OR:

LateUpdate

现在:

Update

返回:

a = [1, 2]
b = [3, 4]
c = [5, 6]
d = [7, 8]
a.extend(b)
a.extend(c)
a.extend(d)