title: How do I create a dictionary mapping strings to sets given a list and a tuple of tuples?
body: <p>I am trying to create a dictionary from a list and tuple of tuples as illustrated below. I have to reverse map the tuples to the list and create a set of non-None column names. </p>
  
  <p>Any suggestions on a pythonic way to achieve the solution (desired dictionary) is much appreciated.</p>
  
  <p><strong>MySQL table 'StateLog':</strong></p>
  
  <pre><code>Name NY   TX   NJ
  Amy  1    None 1
  Kat  None 1    1
  Leo  None None 1
  </code></pre>
  
  <p><strong>Python code :</strong></p>
  
  <pre><code>## Fetching data from MySQL table
  #cursor.execute("select * from statelog")
  #mydataset = cursor.fetchall()
  ## Fetching column names for mapping
  #state_cols = [fieldname[0] for fieldname in cursor.description]
  
  state_cols = ['Name', 'NY', 'TX', 'NJ']
  mydataset = (('Amy', '1', None, '1'), ('Kat', None, '1', '1'), ('Leo', None, None, '1'))
  
  temp = [zip(state_cols, each) for each in mydataset]
  
  # Looks like I can't do a tuple comprehension for the following snippet : finallist = ((eachone[1], eachone[0]) for each in temp for eachone in each if eachone[1] if eachone[0] == 'Name')
  for each in temp:
      for eachone in each:
          if eachone[1]:
              if eachone[0] == 'Name':
                  k = eachone[1]
              print k, eachone[0]
  
  print '''How do I get a dictionary in this format'''            
  print '''name_state = {"Amy": set(["NY", "NJ"]),
                  "Kat": set(["TX", "NJ"]),
                  "Leo": set(["NJ"])}'''
  </code></pre>
  
  <p><strong>Output so far :</strong></p>
  
  <pre><code>Amy Name
  Amy NY
  Amy NJ
  Kat Name
  Kat TX
  Kat NJ
  Leo Name
  Leo NJ
  </code></pre>
  
  <p><strong>Desired dictionary :</strong></p>
  
  <pre><code>name_state = {"Amy": set(["NY", "NJ"]),
                "Kat": set(["TX", "NJ"]),
                "Leo": set(["NJ"])}
  </code></pre>