-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
  • 4
    No to dynamic variables, Yes to dictionaries. Commented Jul 26, 2014 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. Commented Jul 26, 2014 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: gist.github.com/anonymous/22f3b363d834e2bfa818 Commented Jul 26, 2014 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 Commented Jul 27, 2014 at 2:37

1 Answer 1

-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.

Sign up to request clarification or add additional context in comments.

1 Comment

This doesn't answer his question, which is about dynamic variable names.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.