Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def csv_reader(filename):
- ''' gives back a list of every element in the csv file '''
- a = []
- try:
- with open(filename, "r") as csvfile:
- for row in csvfile:
- tmp = row.split(";")
- a.append(tmp[0])
- except FileNotFoundError:
- print("Could not find file, please retry.")
- main()
- return a
- def randomizer(a:list, y:int) -> (list):
- '''it randomizes the elements in a list into different y different teams'''
- b = [[]]
- for num in range(y):
- b.append([])
- for element in a:
- tmp = (random.randrange(0, y+1))
- b[tmp].append(element)
- return b
- def main():
- filename = input("Inserire nome file o path: ")
- if filename[-4:] != '.csv':
- filename = filename + '.csv'
- a = csv_reader(filename)
- y = int(input("Inserire il numero di team: "))
- b = randomizer(a, y)
- print(b)
- main()
Advertisement
Add Comment
Please, Sign In to add comment