Advertisement
AppajiC

Untitled

Sep 29th, 2022
714
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.48 KB | None | 1 0
  1. import csv
  2.  
  3. team_mates = {}
  4.  
  5. with open("CS384 Project Group (Responses) - Form Responses 1.csv") as f:
  6.     reader = csv.DictReader(f)
  7.     data = [dict(row) for row in reader]
  8.  
  9. for row in data:
  10.     if row["Partner 1 Name"] not in team_mates:
  11.         team_mates[row["Partner 1 Name"]] = set()
  12.     if row["Partner 2 Name"] not in team_mates:
  13.         team_mates[row["Partner 2 Name"]] = set()
  14.     if row["Partner 2 Name"] not in team_mates[row["Partner 1 Name"]]:
  15.         team_mates[row["Partner 1 Name"]].add(row["Partner 2 Name"])
  16.     if row["Partner 1 Name"] not in team_mates[row["Partner 2 Name"]]:
  17.         team_mates[row["Partner 2 Name"]].add(row["Partner 1 Name"])
  18.  
  19.  
  20. with open("MultipleTeamMates.csv", "w") as f:
  21.     writer = csv.DictWriter(f, fieldnames=["Name", "Team mates"])
  22.     writer.writeheader()
  23.     for key, value in team_mates.items():
  24.         if len(value) != 1:
  25.             writer.writerow({"Name": key, "Team mates": ",".join(value)})
  26.  
  27. with open("contact_info_for_andriod.csv", "r") as f:
  28.     reader = csv.DictReader(f)
  29.     all_names = [dict(row) for row in reader]
  30.  
  31.  
  32. with open("NotRegistered.csv", "w") as f:
  33.     writer = csv.DictWriter(f, fieldnames=["Name", "Email1", "Email2"])
  34.     writer.writeheader()
  35.     for name in all_names:
  36.         name["Name"] = name["Name"].strip()
  37.         if name["Name"] not in team_mates:
  38.             writer.writerow(
  39.                 {"Name": name['Name'], "Email1": name["Email1"], "Email2": name["Email2"]}
  40.             )
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement