지금까지 파일을 가져오고 새 파일을 만들고 목록을 무작위 화하는 방법을 알아 냈습니다.
파일에서 쓸 항목을 무작위로 목록에서 50 개만 선택하는 데 문제가 있습니까?
def randomizer(input,output1='random_1.txt',output2='random_2.txt',output3='random_3.txt',output4='random_total.txt'):
#Input file
query=open(input,'r').read().split()
dir,file=os.path.split(input)
temp1 = os.path.join(dir,output1)
temp2 = os.path.join(dir,output2)
temp3 = os.path.join(dir,output3)
temp4 = os.path.join(dir,output4)
out_file4=open(temp4,'w')
random.shuffle(query)
for item in query:
out_file4.write(item+'\n')
총 랜덤 화 파일이
example:
random_total = ['9','2','3','1','5','6','8','7','0','4']
첫 번째 임의의 세트 3, 두 번째 임의의 세트 3 및 세 번째 임의의 세트 3을 가진 3 개의 파일 (out_file1 | 2 | 3)을 원합니다 (이 예제의 경우 만들려는 파일은 50이어야 함)
random_1 = ['9','2','3']
random_2 = ['1','5','6']
random_3 = ['8','7','0']
따라서 마지막 '4'는 포함되지 않습니다.
무작위로 지정한 목록에서 50을 어떻게 선택할 수 있습니까?
더 좋은 방법은 원래 목록에서 무작위로 50을 어떻게 선택할 수 있습니까?
무슨 소리 야?
—
O.rka