This document contains code snippets for writing to and reading from files, as well as sorting arrays. The writeToFile function writes data to a CSV file. The readFromFile functions read data from a CSV file either by using the CSV module or splitting lines. The sort function sorts an array using a bubble sort algorithm. The swop function swaps the positions of two elements in an array.
This document contains code snippets for writing to and reading from files, as well as sorting arrays. The writeToFile function writes data to a CSV file. The readFromFile functions read data from a CSV file either by using the CSV module or splitting lines. The sort function sorts an array using a bubble sort algorithm. The swop function swaps the positions of two elements in an array.
This document contains code snippets for writing to and reading from files, as well as sorting arrays. The writeToFile function writes data to a CSV file. The readFromFile functions read data from a CSV file either by using the CSV module or splitting lines. The sort function sorts an array using a bubble sort algorithm. The swop function swaps the positions of two elements in an array.
def readFromFile (col): A = [] inFile = open("name.csv", "r") inCSVFile = csv.reader(inFile) for value in inCSVFile: a = float (value [col]) A.append (a) inFile.close () return A
Reading from File (normal)
def readFromFile (col): A = [] inFile = open("name.csv", "r") for line in inFile: data = line.split (",") A.append (float(data[col])) inFile.close () return A
Sorting Arrays
def sort (A): size = len (A) for i in range (0, size-1): for j in range(i+1, size): if A[j]> A[i]: swop (A,i,j) return A