# Suppose the data file contains lines of numbers, # and each number is a separate data point. >>> #3 56 6 98 >>> #44 6 8 9 10 100 >>> #the string method "split" will help. >>> # >>> x = "hello there my friend " >>> x.split() ['hello', 'there', 'my', 'friend'] # # Suppose the first line of file data.txt contains "55 45 4 3\n" # >>> f = open("data.txt",'r') >>> line = f.readlin() >>> line "55 45 4 3\n" # >>> numStrings = line.split() >>> numStrings ['55', '45', '4', '3'] >>> # create a new list which holds the ints >>> intVals = [] >>> for n in numStrings: intVals.append(int(n)) >>> intVals [55, 45, 4, 3] # >>> # Here are examples using the list method, append. # Also, the examples below show how to use numbers to # index the elements of nested lists. # >>> x = [] >>> x.append(23) >>> x [23] >>> x.append(54) >>> x [23, 54] >>> x1 = [0,1,2] >>> x2 = [3,4,5] >>> x.append(x1) >>> x [23, 54, [0, 1, 2]] >>> x[0] 23 >>> x[1] 54 >>> x[2] [0, 1, 2] >>> x.append(["jkfd","jd","jj"]) >>> x [23, 54, [0, 1, 2], ['jkfd', 'jd', 'jj']] >>> x[3] ['jkfd', 'jd', 'jj'] >>> x[3][1] 'jd' >>>