Calculating score of merged string
<p>I am trying to figure out how to calculate the score of two merged lists of names. I need to give one point for each character (including spaces between first and last name) plus one point for each vowel in the name. </p>

<pre><code>a = ["John", "Kate", "Oli"]
b = ["Green", "Fletcher", "Nelson"]

vowel = ["a", "e", "i", "o", "u"]

gen = ((x, y) for x in a for y in b)

for u, v in gen:
    print u, v
</code></pre>

<p>I am struggling to figure out what to do. Any help would be greatly appreciated.</p>

<p>So you first <code>zip</code> first and last names, then make then <code>str</code> with <code>' '</code> as separator. And then with <a href="https://docs.python.org/3/library/collections.html#collections.Counter" rel="nofollow"><code>collections.Counter</code></a> count how many times so called <em>vowel</em> characters occur, <code>sum</code> them up, and add <code>len</code> of whole name. And that would be <code>dict</code> object, then you can do whatever you like with it.</p>

<pre><code>from collections import Counter

a = ["John", "Kate", "Oli"]
b = ["Green", "Fletcher", "Nelson"]    
vowel = ["a", "e", "i", "o", "u"]

output = {}
for item in [' '.join(i) for i in zip(a,b)]:
    output[item] = sum(Counter(item)[x] for x in vowel) + len(item)
output
</code></pre>

<p>Output:</p>

<pre><code>{'John Green': 13, 'Kate Fletcher': 17, 'Oli Nelson': 13}
</code></pre>

<p><strong>UPDATE</strong></p>

<p>If you need all possible variations of first name and last name you can do that with <a href="https://docs.python.org/3/library/itertools.html#itertools.product" rel="nofollow"><code>itertools.product</code></a></p>

<pre><code>from itertools import product
from collections import Counter

a = ["John", "Kate", "Oli"]
b = ["Green", "Fletcher", "Nelson"]    
vowel = ["a", "e", "i", "o", "u"]

output = {}
for item in [' '.join(i) for i in product(a,b)]:
    output[item] = sum(Counter(item)[x] for x in vowel) + len(item)
output
</code></pre>

<p>Output:</p>

<pre><code>{'John Fletcher': 16,
 'John Green': 13,
 'John Nelson': 14,
 'Kate Fletcher': 17,
 'Kate Green': 14,
 'Kate Nelson': 15,
 'Oli Fletcher': 15,
 'Oli Green': 12,
 'Oli Nelson': 13}
</code></pre>

python string list