# tasks: # 1 create a nested list of integers in Python # 2 write it to a csv file # 3 read it back, # 4(a) double one number... 4(b) every number # 1 - manually create a straight forward nested list ints=[ [3,6,8,3], [1,8,2,6], [9,4,2,7] ] # 1 - using "list comprehension" can be used to generate lists very quickly... import random i=[[random.randint(1,100) for each in range(10)] \ for every in range(5)] # nested list containing 5 lists, each of 10 random numbers. print(i) #2 import csv with open("ints.csv", 'w', newline='') as csvfile: #prepare csv file for writing writer = csv.writer(csvfile) # use the .writer() method to create a variable called writer that Python can write to. writer.writerows(ints) # write the list to the file #3 list_name=[] with open("ints.csv") as csvfile: reader = csv.reader(csvfile) for row in reader: list_name.append(row) print(list_name) ###4(a) double one number ##ints[2][3]=int (ints[0][1])*2 ## ###4(b) every number ##num_rows=len(ints) ##num_cols=len(ints[0]) #length of 1st row gives you #columns ##for row in range(0,num_rows): ## for col in range(0,num_cols): ## ints[row][col]=int (ints[row][col])*2 ##print(ints)