Q:

Adding an empty space in list in python

I want to analyze some data (one x-value, several y-values). Unfortunately not every x-value has all y-values filled, some values are empty. I want to put all values into lists, so that I have a x-value-list ([1, 2, 3, 4]) and an y-value-list ([[1, 2], [1, 4], [5, 2]]). But if I want to add an element into the list, it has to be a number (after my lists are float lists). Later I want to use these lists to plot the data. Thus I have the problem that I have to add a value to the list while parsing the data, but later I have to omit these values again for plotting, otherwise I get wrong results. My first idea was to simply add an empty space in the list, so that the plotting program skips this value. But that is not allowed to do in python.
What is the best way to circumvent my problem?

A:

Create a DataPoint class that can hold x and y values and put them in a single list. Then you can set the y value to none (or an empty list) for the points that have missing values.
This also ensures you have a valid set of points at all times. You could enter an empty list for when there is no y value but you still run the risk of the x and y lists being out of sync.

