I have data of the following form:
list_of_numbers = [[8, 10], [10, 8, 1, 0], [6], [4, 0, 1, 2, 3], [12]]
I am trying to extract the first and second element of this list as follows:
[n[0] for n in list_of_numbers]
This works well for the first element, however, when I try to extract the second element in the same way I get an error (IndexError: list index out of range). I realise this is because the some of the lists in the list do not have a second element. However, I need to extract the second element whenever it exists, and have NaN/missing when it doesn't. How do I go about implementing this in my code?
Thanks!