Q:

Looping through a list of strings and tuples and appending unique combinations

I have been working on this looping problem for a bit now. How do I loop through a list containing a single string and tuple, while appending the tuple to the preceding string? For example:
gen = ['A', ('x', 'y'), ('t', 'u'), 'B', ('y', 't'), 'B', ('a', 'z')]
fam = ['A', 'B']

Fortunately fam also contains the single strings imbeded within gen. In the end I would like the following. 
result = [('A',('x','y')), ('A', ('t', 'u')), ('B', ('y', 't')), ('B', ('a', 'z'))

Notice that the tuples following a single string (e.g. 'A') are appending to it. 
How do I loop through gen so that the tuples are appending with single strings preceeding it? So far, I have something like the following. Which appends all the combinations in the gen, and then some. I foolishly created a duplicate gen, i.e. gen2 to help with looping, to no avail.
gen = ['A', ('x', 'y'), ('t', 'u'), 'B', ('y', 't'), 'B', ('a', 'z')]
fam = ['A', 'B']
gen2 = ['A', ('x', 'y'), ('t', 'u'), 'B', ('y', 't'), 'B', ('a', 'z')]

result = []
for f in fam:
    for g in gen:
        if len(g) == 2:
            for g2 in gen2:
                if g2 == f:
                    result.append((g2,f))
print result

I apologize if my ramble is too confusing. I appreciate any insight.

A:

You can do it in a single loop and without using fam if you keep track of the last string you came across. It only works properly if the first element of gen is a string, though.
gen = ['A', ('x', 'y'), ('t', 'u'), 'B', ('y', 't'), 'B', ('a', 'z')]

result = []
lastStringSeen = None
for i in gen:
    if isinstance(i, str):
        lastStringSeen = i
    else: #must be a tuple
        result.append((lastStringSeen, i))
print result

output: 
[('A', ('x', 'y')), ('A', ('t', 'u')), ('B', ('y', 't')), ('B', ('a', 'z'))]

