I have a large text file containing many thousand lines but a short example that covers the same idea is:
vapor dust -2C pb
x14 71 hello! 42.42
100,000 lover baby: -2
there is a mixture of integers, alphanumerics, and floats.
ATTEMPT AT SOLN. Ive done this to create a single list composed of strings, but I am unable to isolate each cell based on if its numeric or alphanumeric
with open ('file.txt','r') as f:
data = f.read().split()
#dirty = [ x for x in data if x.isnumeric()]
print(data)
The line #dirty
fails.
I have had luck constructing a list-of-lists containing almost all required values using the code as follows:
with open ('benzene_SDS.txt','r') as f:
for word in f:
data= word.split()
clean = [ x for x in data if x.isnumeric()]
res = list(set(data).difference(clean))
print(clean)
But It doesnt return a single list, it a list of lists, most of which are blank [].
There was a hint given, that using the "try" control statement is useful in solving the problem but I dont see how to utilize it.
Any help would be greatly appreciated! Thanks.