-1

I am new to Python, and I have no idea how to do this. Any help would be greatly appreciated.

  1. I have 2 files that I am reading in : yesterday's people list and today's people list
  2. I am attempting to diff these 2 lists and print out the differences in the output
  3. One of the columns that I am comparing is the Supervisor for a given person yesterday and today
  4. Often, there are multiple people who have all have been moved from Supervisor A to Supervisor B
  5. I want to create a set whose name is SupervisorA_SupervisorB and then add the names of all the people who have moved from Supervisor A to Supervisor B, and then later print the set.
  6. How do I create a variable with a dynamic name, since the Supervisor A and B could be C, D, E, etc.

I suspect many of you will suggest dictionaries and that is fine, but I am trying to add multiple Employees to a Old-Supervisor_New-Supervisor variable. I'm still not clear on how to go about doing that.


Dynamic variables may not be the solution, and I am fine with that. The output I'm looking for is something like this

Sup A --> Sup B

Bill Harry Sally

Sup D --> Sup C

John Matt

Sup N --> Sup L

Steve Jen Sue Rob

So in case, there were multiple people who had a specific Supervisor change.

  • 4
    No to *dynamic variables*, Yes to [*dictionaries*](https://docs.python.org/3.4/library/stdtypes.html#mapping-types-dict). – user2864740 Jul 26 '14 at 20:29
  • 1
    "I suspect many of you will suggest dictionaries and that is fine, but I am trying to add multiple Employees to a Old-Supervisor_New-Supervisor variable. I'm still not clear on how to go about doing that." This is us telling you specifically _not_ to do that, because it's not a very good idea. Especially if you have to dynamically put the variable name together every time you access the variable, there is no good reason not to use a dictionary. – TheSoundDefense Jul 26 '14 at 20:42
  • @mixingbuddha: You just need to make a dictionary where the keys are (old_supervisor, new_supervisor) tuples. Here's a simple example I just whipped up: https://gist.github.com/anonymous/22f3b363d834e2bfa818 – Daniel Pryden Jul 26 '14 at 21:29
  • @DanielPryden - That was awesome! Thanks so much. I'm still not sure I completely understand it, but I got it to work – mixingbuddha Jul 27 '14 at 02:37

1 Answers1

-1

Use set() Unordered collections of unique elements. It supports operations like union, intersection, difference... Make one for 'yesterday' and one for 'today' and apply the desired operatio.

f.rodrigues
  • 3,499
  • 6
  • 26
  • 62