I have read a file into the Python script using:
data=np.loadtxt('myfile')
Which gives a list of numbers of type 'numpy.ndarray', in the form:
print(data) = [1, 2, 3]
I need to convert this into a list of lists, each with a single-character string 'a' and one of the above values, i.e.:
[[a,1],
[a,2],
[a,3]]
(Note that 'a' does not differ between each of the lists, it remains as a string consisting simply of the letter 'a')
What is the fastest and most Pythonic way of doing this? I have attempted several different forms of list comprehension, but I often end up with lines of 'None' displayed. The result does not necessarily have to be of type 'numpy.ndarray', but it would be preferred.
Also, how could I extend this method to data that has been read in from the file already as a list of lists, i.e.:
data2=np.loadtxt('myfile2',delimiter=' ')
print(data2)= [[1,2],
[3,4],
[5,6]]
To give the result:
[[a,1,2],
[a,3,4],
[a,5,6]]
Thank you for the help!