title: Conditional positional comparison of lists based on
body: <p>I asked a similar question recently, but the error message and problem changed a bit.</p>
  
  <p>I would like to create multiple lists that are dependent on the previous list based on the position of items in each list</p>
  
  <p>So for example list 1 would read a specific file and return either a number or the boolean false based on a comparison.</p>
  
  <p>The second list would then compare the number that appears in the same position as those in the previous list (if the value from the previous list was not false) and return the value or false based on the same comparison as the first list</p>
  
  <p>Examples of dataframes:</p>
  
  <pre><code>a = pd.DataFrame([0,0.9,0.6,0.7,0.8])
  b = pd.DataFrame([0.7,0.51,0.3,0.7,0.2])
  </code></pre>
  
  <p>I created a function that carries out these comparisons and creates a list</p>
  
  <pre><code>def generic_state_machine(file,obs_nums):
      return file.ix[:,0][obs_nums] if file.ix[:,0][obs_nums] &gt; 0.2 else False
  </code></pre>
  
  <p>obs_nums in this context refers to the position of an item in a list</p>
  
  <p>I then created the lists that look at different files</p>
  
  <pre><code>session_to_leads = []
  lead_to_opps = []
  
  for i in range(1,len(a)):
       session_to_leads.append(generic_state_machine(file=a,obs_nums=i))
       lead_to_opps.append(generic_state_machine(file=b,obs_nums=i)) if session_to_leads != False else lead_to_opps.append(False)
  </code></pre>
  
  <p>I managed to sort out the initial error I encountered, the only problem now is that list lead_to_opps is not dependent on session_to_leads so if there is a False value in position 1, lead_to_opps will not automatically return a False in the same position. So assuming that random.uniform(0,1) generates 0.5 all the time, this is my current outcome:</p>
  
  <pre><code>session_to_leads = [False,0.9,0.6,0.7,0.8]
  lead_to_opps = [0.7,0.51,False,0.7,False]
  </code></pre>
  
  <p>This is my desired outcome:</p>
  
  <pre><code>session_to_leads = [False,0.9,0.6,0.7,0.8]
  lead_to_opps = [False,0.51,False,0.7,False]
  </code></pre>