Python - match/lookup

Python - match/lookup

我有两个列表,都包含几千个列表。 第一个列表是一个股票交易列表,其中的每个列表都是一个单独的交易,格式为

(datetime.date, str, str, int)

第二个列表是收盘价列表,其中每个列表的格式为

 (datetime.date, str, float)

我需要将第一个(主)列表中的所有列表附加到第二个列表中的相关收盘价数据,匹配日期时间和第一个元组(证券)。基于这两个变量创建一个 match/lookup 函数已经证明超出了我的能力,任何帮助设置它都将不胜感激。

我的代码如下:

for tradeline in tradeslist:
    for eodpriceline in eodpriceslist:
            if tradeline[0]==eodpriceline[0] and tradeline[1]==eodpriceline[1]
            print(eodpriceline[3])

但我得到的错误是:

    if tradeline[0]==eodpriceline[0] and tradeline[1]==eodpriceline[1]
                                                                    ^
SyntaxError: invalid syntax

您忘记了 if 语句末尾的冒号 :

if tradeline[0]==eodpriceline[0] and tradeline[1]==eodpriceline[1]

应该是:

if tradeline[0]==eodpriceline[0] and tradeline[1]==eodpriceline[1]: