title: Choosing elements in an array randomly - satisfying conditions
body: <p>I need help for my project. The following are the sample data.</p>
  
  <pre><code>populations = [[1 1]
                 [1 1]
                 [1 0]
                 [1 1]]
  
  score = [0, 4, 0, 6]
  avail_res = [4, 4]
  </code></pre>
  
  <p>Code looks like this:</p>
  
  <pre><code>chromosome = []
  for num in score:
      if num &lt;= avail_res[0] and num != 0:
          chromosome = populations[score.index(num)]
          print(chromosome)
  
          if len(chromosome) &gt; 1:
             k = random.choice(chromosome)
             chromosome_best = [k[1]]
             print(chromosome_best)
  
          else:
             chromosome_best = [chromosome]
             print(chromosome_best)
  </code></pre>
  
  <p>The objective is to find the best chromosome among the chosen chromosome/s. For the example above, since only <code>4</code> (score index 1) satisfies the condition in the code, it should give <code>chromosome best = [1 1]</code> from populations. In cases that there are more than one score that satisfy the condition, the code should choose the best_chromosome, randomly. For example, <code>score = [4, 2, 2, 6]</code>. I have three elements in score that satisfy the condition (4, 2, 2). Now, in choosing the best_chromosome in populations, the code can choose the one that is higher, which is 4 and give the corresponding value in populations.</p>
  
  <p>The problem is whenever I try to run the code, for the chosen <code>chromosome_best = [1 0]</code> (just an example), The length that I am getting is <code>2</code>, which corresponds for 1 and 0. But my intent is just to get <code>length = 1 for [1 0]</code> and <code>3</code> if the chromosomes are <code>[1 0] [1 1] [1 0]</code>. In this way, I could use the code above and choose randomly.</p>
  
  <p>Any help/suggestion would be appreciated! Thanks!</p>