了解1行循环

时间:2019-06-19 15:08:43

标签: python

我正在尝试理解这一行代码。似乎它是一个“循环”,但不确定如何分解。有人可以帮忙将其重写为标准的“ for-loop”,以便我看看发生了什么吗? (实际上是否为for循环)

i = [money[i+1] - money[i] for i in range(len(money)-1)]

date = []
money = []

with open(budget_data_path, newline="", encoding="utf8") as budget_data:
    csvreader = csv.reader(budget_data, delimiter=",")
    next(csvreader)
    for row in csvreader:
        date.append(str(row[0]))
        money.append(int(row[1]))
        #iterates through and adds the 2nd value to the previous
        i = [money[i+1] - money[i] for i in range(len(money)-1)]

0 个答案:

没有答案