My script in progress:
def plotRegression(data):
'''read labdata.txt and plot
x,y coordinates using formula'''
import turtle
wn = turtle.Screen()
t = turtle.Turtle()
t.speed()
#set up variables
x_list = [i[0] for i in data]
y_list = [i[1] for i in data]
#formula goes here
#set window size here
with open("labdata.txt") as f:
#coords = [map(int, line.split()) for line in f]
coords = list(map(int, line.split()) for line in f)
plotRegression(coords)
labdata.txt sample:
44 71
79 37
78 24
Error when running script:
Traceback (most recent call last):
File "plot_regression.py", line 23, in <module>
plotRegression(coords)
File "plot_regression.py", line 12, in plotRegression
x_list = [i[0] for i in data]
File "plot_regression.py", line 12, in <listcomp>
x_list = [i[0] for i in data]
TypeError: 'map' object is not subscriptable
My goal from this question is to read the data from labdata.txt and have the data ready as integers for the function to read. I think I have overcomplicated things at this point but I have something to learn so your help is appreciated!
In the with statement I have commented out a line. I saw this map method for the first time in someone else's code and I wanted to give it a shot as it seemed useful. However, after some errors and research it looks like this is Python 2 code and I am using Python 3 so there are some differences which will not allow me to run the code properly.
Searches here on stackoverflow explain that the map function "returns a generator" but I am not sure what that means. Can someone explain to me why my attempt is not working?