我從寫入文件的列表中獲取30 n個隨機樣本。從隨機樣本中寫出
我寧願在末尾寫入「in_sample」或「not_in_sample」來標記要寫入示例的行。
現在看起來是這樣的:
mysample=random.sample(list, 30)
for i in mysample:
out.write("%s\n" % (i))
我只寫了從樣本行,但我想這個文件,看起來像這樣:
line 1 in_sample
line 2 not_in_sample
line 3 in_sample
line 4 not_in_sample
文件看起來都一樣過,但沒有最後一欄。
我清楚嗎?
我編輯 – AWE 2012-02-28 16:24:28
@AWE之前用你的回答:您歡迎!我從舊的編輯中恢復了這2行:) – 2012-02-28 16:27:21