Max, len, split Python
<p>I'm trying to find all combinations of A,B repeated 3 times.
Once I've done this I would like to count how many A's there are in a row, by splitting the string and returning the len.max value. However this is going crazy on me. I must have misunderstood the len(max(tmp.split="A")</p>

<p>Can anyone explain what this really does (len returns the length of the string, and max returns the highest integer of that string, based on my split?) I expect it to return the number of A's in a row. "A,B,A" should return 1 even though there are two A's. </p>

<p>Suggestions and clarifications would be sincerely welcome</p>

<pre><code>import itertools
list = list(itertools.product(["A", "B"], repeat=3))

count = 0;

for i in list:
    count += 1;
    tmp = str(i);
    var = len(max(tmp.split("B")))
    print(count, i, var)
</code></pre>

<p><strong>Edit</strong>: Count only consecutive B's</p>

<pre><code>import re
import itertools
li = list(itertools.product(["A", "B"], repeat=3))

count = 0;

for i in li:
    count += 1
    s = ''.join(i)
    if i.count('B') &gt; 0:
        var  = max(len(s) for s in re.findall(r'B+', s))
    else:
        var = 0
    print(count, i, var)
</code></pre>

python itertools