I have an input string, each element has a number and character which I want to access each element number and character separately as the following:
1s-2r,3d*3 # this is the line in the input file: # this stars means repeated three time
So I want to make an array includes only numbers as:
number_only=[1,2,3,3,3] # numpy
s=[s,r,d,d,d] # another array string characters only
But I got the following erros "TypeError: can't multiply sequence by non-int of type 'str'".. I know that this should be a intger but I do not know how to do that, attached is the trial code
import numpy as np
with open('dataa.dat', 'r') as f:
input_data = f.readlines()
input_data = [(d+' ')[:d.find('#')].rstrip() for d in input_data]
x = input_data[0].split('-')
y = []
for elt in x:
if "*" in elt:
n, mult = elt.split("*")
y = y + [(n)] * (mult)
else:
y+=[ii for ii in elt.split(',')]
number_only = np.array(y)
#s