Combine lists from two lists of list into a single list of lists def combine_in_place(first, second):
    combined = []
    maxLength = max(len(first), len(second))
    for i in range(maxLength):
        if len(first) &lt; i+1:
            combined.append(second[i])
        elif len(second) &lt; i+1:
            combined.append(first[i])
        else:
            if not first[i]:
                combined.append(second[i])
            elif not second[i]:
                combined.append(first[i])
            else:
                combined.append(first[i] + second[i])

    return combined


print combine_in_place([['f'], ['j', 't'], [], ['s'], [], []], [['h', 'd'], [], [], []])
    # prints: [['f', 'h', 'd'], ['d', 't'], [], ['s'], [], []]


So I know to program (been programming in Java for some time now). I am trying to learn Python but I am not sure what's the best way to do some stuff. My question is:
How to write the function in a more Pythonic way?
I would write something like that:

def combine(first, second):
    ret_list = []
    for i, j in zip(first, second):
        add = []
        if i is not None:
            add.extend(i)
        if j is not None:
            add.extend(j)
        ret_list.append(add)
    return ret_list


I don't know if it is the most python-ish way but it is ok I think...

I mean you can also write something like this:

def combine(first, second):
    return [(i.extend(j) if not (i is None or j is None) else i if j is None else j) for i, j in zip(first, second)]


But you cannot read and debug that. So I would strongly recommend against it.

Btw: Did not test the last one so I hope I did not forget a closing bracket ;)

Edit:

In order to keep all elements you have to add something to the end. The zip() function stops iterating after the shortest element reached its end.
This is why the following method is needed instead of zip:

def combine(first, second):
    ret_list = []
    for i, j in itertools.zip_longest(first, second):
        add = []
        if i is not None:
            add.extend(i)
        if j is not None:
            add.extend(j)
        ret_list.append(add)
    return ret_list


Note: Itertools simply must be imported first. (For Python2 it is itertools.izip_longest()...)