with open('wdbc.data', 'r') as f:
    data = [line.strip().split(',') for line in f if line.strip()]

slices = [
    (0, 300, 'train'),
    (300, len(data), 'validate')
]

for init, finish, label in slices:
    b_data = []
    a_data = []
    
    for row in data[init:finish]:
        if row[1] == 'B':
            b_data.append('-1') # 良性 benign
        else:
            b_data.append('1')  # 悪性 malignant
            
        a_data.append(' '.join(str(float(x)) for x in row[2:]))

    with open(f"{label}_b.data", 'w') as fb:
        fb.write('\n'.join(b_data))
        
    with open(f"{label}_A.data", 'w') as fa:
        fa.write('\n'.join(a_data))