title: Most efficient way to replace every possible combination of up to N items in a tuple in Python?
body: <p>If I have a tuple of a generic length. Given a specific N, what is the most efficient way to create every single possible combination of the tuple where the token <code>&quot;&quot;</code> replaces up to N items in the tuple?</p>
  <p>For example, non efficient way of doing this</p>
  <pre><code> def create_feature_graph(l,N):
       all_combinations = list(set(product(*zip(l, repeat('')))))
       all_combinations = [x for x in all_combinations if x.count('') &lt;= N]
       return all_combinations
  
  l = ('A','B','C')
  print(create_feature_graph(l,1))
  [('A','B','C'),('','B','C'),('A','','C'),('A','B','')]
  </code></pre>
  <p>The current implementation first creates the following list</p>
  <pre><code>[('A','B','C'),('','B','C'),('A','','C'),('A','B',''),('','','C'),('',B,''),('A','',''),('','','')]
  </code></pre>
  <p>Before filtering for every item which consists of up to N occurences of <code>&quot;&quot;</code>, which is not very efficient for large lists.</p>
  <p>What would be a smart and more efficient way of doing this?</p>