Python練習—分組

※第一週在進行分組並實際換好座位後,我們將座位填上線上表格Ethercalc中,並擷取後利用Python進行分組練習,規則為一組三人,共會分成14組。

1.分組排列程式展示

with open("2a raw.txt") as fh:
    rea = fh.readlines()
    #print (rea)

no_list = lambda list: int((sum([(len(list[i])) for i in range(len(list))]))/3)
#簡寫一個for迴圈命名為no_list,目的為求出迴圈執行次數(14次)

t = list()#命名空清單t
for k in range(len(rea)):
    a = rea[k]
    b = a.split()#分割每一行第k位
    #print(b)
    for i in range(0,len(b),3):
        c = b[i:i+3]#每三字串為一次進行迴圈
        t.append(c)#加入清單t
        
for g in range(no_list(t)):#range = 14
    print("第" + str(g+1) + "組:" + str(t[g]))

2.輸出的結果

第1組:['40523115', '40523108', '40523116']
第2組:['40523144', '40523111', '40523141']
第3組:['40523104', '40523102', '40523123']
第4組:['40523137', '40523117', '40523135']
第5組:['40523147', '40523146', '40523145']
第6組:['40523122', '40523136', '40523132']
第7組:['40523127', '40523126', '40523125']
第8組:['40523124', '40523118', '40523131']
第9組:['40523121', '40523120', '40523119']
第10組:['40523105', '40523106', '40523107']
第11組:['40523143', '40523128', '40523129']
第12組:['40523130', '40523139', '40523133']
第13組:['40523142', '40523148', '40523140']
第14組:['40523113', '40523138', '40523134']

詳細內容可至本組網誌查看:https://s40523123.github.io/cd2018/2018/03/08/group3-W1/

Last updated