Q:

Adding values from one list to another when they share value

I'm trying to add values from List2 if the type is the same in List1. All the data is strings within lists. This isn't the exact data I'm using, just a representation. This is my first programme so please excuse any misunderstandings.
List1 = [['Type A =', 'Value 1', 'Value 2', 'Value 3'], ['Type B =', 'Value 4', 'Value 5']]
List2 = [['Type Z =', 'Value 6', 'Value 7', 'Value 8'], ['Type A =', 'Value 9', 'Value 10', 'Value 11'], ['Type A =', 'Value 12', 'Value 13']]

Desired result:
new_list =[['Type A =', 'Value 1', 'Value 2', 'Value 3', 'Value 9', 'Value 10', 'Value 11', 'Value 12', 'Value 13'], ['Type B =', 'Value 4', 'Value 5']]

Current attempt:
newlist = []
for values in List1:
    for valuestoadd in List2:
        if values[0] == valuestoadd[0]:
            newlist = [List1 + [valuestoadd[1:]]]
        else:
            print("Types don't match")
    return newlist

This works for me if there weren't two Type A's in List2 as this causes my code to create two instances of List1. If I was able to add the values at a specific index of the list then that would be great but I can work around that.

A:

It's probably easier to use a dictionary for this:
def merge(d1, d2):
    return {k: v + d2[k] if k in d2 else v for k, v in d1.items()}

d1 = {'A': [1, 2, 3], 'B': [4, 5, 6]}
d2 = {'A': [7, 8, 9], 'C': [0]}
print(merge(d1, d2))

If you must use a list, it's fairly easy to temporarily convert to a dictionary and back to a list:
from collections import defaultdict

def list_to_dict(xss):
    d = defaultdict(list)
    for xs in xss:
        d[xs[0]].extend(xs[1:])
    return d

def dict_to_list(d):
    return [[k, *v] for k, v in d.items()]

