Skip to content

Instantly share code, notes, and snippets.

@ammar-faifi
Created July 28, 2023 07:42
Show Gist options
  • Save ammar-faifi/1451f09eea5ba92c1043d1c8855e3b5d to your computer and use it in GitHub Desktop.
Save ammar-faifi/1451f09eea5ba92c1043d1c8855e3b5d to your computer and use it in GitHub Desktop.
read and shuffle CSV names into groups in terminal
import random
def read_csv(file_path):
with open(file_path, "r") as file:
lines = file.readlines()
rows = [line.strip().split(",") for line in lines]
return rows
if __name__ == "__main__":
# read raw CSV as rows
csv_file = "/Users/ammar-imac/Downloads/names.csv"
data = read_csv(csv_file)
# extract names, and drop header
names = [line[0] for line in data][1:]
# shuffle names
random.shuffle(names)
# convert list to set
names = set(names)
while names:
group_size = int(input("\n\nEnter the size of each group: "))
print("#" * 40)
for _ in range(group_size):
try:
print(names.pop())
except KeyError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment