Amanda_11 0 Newbie Poster

Hello All,

I am working on a python project that helps pull random names from a list in excel and saves them to a new excel file. The input file shows all of the names of the people who can work on that task. I am able to run the code below and get a random list for each task but I end up with duplicates down my lists. I am trying to create restraints to not allow duplication down the rows also but cant seem to get it to work.

import random
import xlrd
import openpyxl as pyxl

inputFilename = 'Rotation_Task_Names.xlsx'

wb = pyxl.load_workbook(inputFilename)
wb.save(inputFilename)
wb.close()

newFilename = 'Rotation_Task_Schedule.xlsx'

sh = xlrd.open_workbook('Rotation_Task_Names.xlsx').sheet_by_index(0)

Amex_LT = sh.col_values(0, start_rowx=1)
Amex_LT = list(set(Amex_LT))
Amex_LT.remove('')
Wood_PP = sh.col_values(1, start_rowx=1)
Wood_PP = list(set(Wood_PP))
Wood_PP.remove('')
Athens_PP = sh.col_values(2, start_rowx=1)
Athens_PP = list(set(Athens_PP))
Athens_PP.remove('')
Wood_Room = sh.col_values(3, start_rowx=1)
Wood_Room = list(set(Wood_Room))
Wood_Room.remove('')
Wood_LT = sh.col_values(4, start_rowx=1)
Wood_LT = list(set(Wood_LT))
Wood_LT.remove('')
PI_Report = sh.col_values(5, start_rowx=1)
PI_Report = list(set(PI_Report))
PI_Report.remove('')
Assign_Issues = sh.col_values(6, start_rowx=1)
Assign_Issues = list(set(Assign_Issues))
Heijunka = sh.col_values(7, start_rowx=1)
Heijunka = list(set(Heijunka))
Stand_Up = sh.col_values(8, start_rowx=1)
Stand_Up = list(set(Stand_Up))

wb = pyxl.load_workbook(newFilename)
ws = wb.worksheets[0]

for week in range(0,8):
  templist = [random.choice(Amex_LT).strip()]
  while templist:
    WoodPP = (random.choice(Wood_PP).strip())
    if WoodPP not in templist:
      templist.append(WoodPP) 
      break
  while templist:
    AthensPP = (random.choice(Athens_PP).strip())
    if AthensPP not in templist:
      templist.append(AthensPP) 
      break
  while templist:
    WoodRoom = (random.choice(Wood_Room).strip())
    if WoodRoom not in templist:
      templist.append(WoodRoom) 
      break
  while templist:
    WoodLT = (random.choice(Wood_LT).strip())
    if WoodLT not in templist:
     templist.append(WoodLT) 
     break  
  while templist:
    PIReport = (random.choice(PI_Report).strip())
    if PIReport not in templist:
      templist.append(PIReport) 
      break
  while templist:
    AssignIssues = (random.choice(Assign_Issues).strip())
    if AssignIssues not in templist:
      templist.append(AssignIssues) 
     break 
  while templist:
    Heijunkalist = (random.choice(Heijunka).strip())
    if Heijunkalist not in templist:
      templist.append(Heijunkalist) 
      break
  while templist:
    StandUp = (random.choice(Stand_Up).strip())
    if StandUp not in templist:
      templist.append(StandUp) 
      break
  for column in range(1,10):
    ws.cell(row = week+2, column = column).value = templist[column-2]
wb.save(newFilename)
wb.close()