First, this is what I have on the code so far, I'll give the explanation in a bit:
ll1 = [
'A',
'B',
'C',
'D'
]
l2 = [
['A', 10],
['B', 20],
['D', 5],
['A', 15],
['B', 30],
['C', 10],
['D', 15]
]
dc = dict(l2)
l3 = [[k, dc.get(k, 0)] for k in l1]
The result is this:
['A', 15]
['B', 30]
['C', 10]
['D', 15]
The first list l1 is made of a fixed number of keys and the second list l2 has the values to each key given in the first list. The l2 here is just one example as I'll be getting the values later (and these values are will be given as a list) but they'll have the same keys as l1. Every key needs to be shown, a key can be repeated, but some keys may have a null value (eg. the item C).
But when the list becomes the dict, the first value of each key is thrown away, returning unique keys for the dictionary.
How could it be done so that the result is similar to this one below?
['A', 10]
['B', 20]
['C', 0]
['D', 5]
['A', 15]
['B', 30]
['C', 10]
['D', 15]
Another example would be:
database_keys = [
'First Name',
'Last Name',
'Email',
'City'
]
database_input = [
['First Name', 'John'],
['Last Name', 'Doe'],
['Email', 'johndoe@test.com'],
['First Name', 'Jane'],
['Email', 'jane@test.com']
]
Output:
['First Name', 'John']
['Last Name', 'Doe']
['Email', 'johndoe@test.com']
['City', None]
['First Name', 'Jane']
['Last Name', None]
['Email', 'jane@test.com']
['City', None]