Hi I try to get training set from a file and return a list of a pair of tuples like here [('yes', 40, 'good'),('more'), ...]
I tried to do it in this way
[('yes', 40, 'good'),('more',), ...] with the comma in the second tuple
what i really want is to remove the comma at the second tuple
Code
def gettrain():
# >>>>> YOUR CODE HERE
with open('health-train.txt','r') as health_test:
d = list()
lable = list()
Data = (line.strip().split(',') for line in health_test)
#Data = [(smoke, int(age), diet, lable) for smoke, age, diet, lable in Data]
for smoke, age, diet, lable in Data:
d.extend([(smoke, int(age), diet), (lable,)])
return d
# <<<<< END YOUR CODE
Output:
[('yes', 54, 'good'),
('less',),
('no', 55, 'good'),
('less',),
('no', 26, 'good'),
('less',),
('yes', 40, 'good'),
('more',),
('yes', 25, 'poor'),
('less',),
('no', 13, 'poor'),
('more',),
('no', 15, 'good'),
('less',),
('no', 50, 'poor'),
('more',),
('yes', 33, 'good'),
('more',),
('no', 35, 'good'),
('less',),
('no', 41, 'good'),
('less',),
('yes', 30, 'poor'),
('more',),
('no', 39, 'poor'),
('more',),
('no', 20, 'good'),
('less',),
('yes', 18, 'poor'),
('less',),
('yes', 55, 'good'),
('more',)]