First, array_length should be an integer and not a string:
array_length = len(array_dates)
Second, your for loop should be constructed using range:
for i in range(array_length): # Use `xrange` for python 2.
Third, i will increment automatically, so delete the following line:
i += 1
Note, one could also just zip the two lists given that they have the same length:
import csv
dates = [‘2020-01-01’, ‘2020-01-02’, ‘2020-01-03’]
urls = [‘www.abc.com’, ‘www.cnn.com’, ‘www.nbc.com’]
csv_file_patch = ‘/path/to/filename.csv’
with open(csv_file_patch, ‘w’) as fout:
csv_file = csv.writer(fout, delimiter=’;’, lineterminator=’n’)
result_array = zip(dates, urls)
csv_file.writerows(result_array)
I had same error and the mistake was that I had added list and dictionary into the same list (object) and when I used to iterate over the list of dictionaries and use to hit a list (type) object then I used to get this error.
Its was a code error and made sure that I only added dictionary objects to that list and list typed object into the list, this solved my issue as well.