I have a string of plot ploints such as:
plots = [(0, 1), (0, 2), (1, 4), ... (0.4, 0.8) etc
But I want to split them into respective x and y's:
x = (0, 0, 1, ... 0.4)
y = (1, 2, 4, ... 0.8)
I am unsure how to do this.
I have a string of plot ploints such as:
plots = [(0, 1), (0, 2), (1, 4), ... (0.4, 0.8) etc
But I want to split them into respective x and y's:
x = (0, 0, 1, ... 0.4)
y = (1, 2, 4, ... 0.8)
I am unsure how to do this.
python provides you with the zip() function
x, y = zip(*plots)
which would provide your exact need, the asterisk would unpack the list into tuples, than the zip function "zips" the tuples together, that is creates a tuple for each index of the tuples
plots = [(0, 1), (0, 2), (1, 4), (0.4, 0.8)]
x = [plot[0] for plot in plots]
y = [plot[1] for plot in plots]
This could be an inline solution
plots = [(0, 1), (0, 2), (1, 4)]
x, y = [item[0] for item in plots], [item[1] for item in plots]