Suppose that i have:
l = [
['Brasil', 'Italia', [10, 9]],
['Brasil', 'Espanha', [5, 7]],
['Italia', 'Espanha', [7,8]],
]
and an empty dict:
d = {}
I'm trying to do this operation in an dict comprehension:
for x in l:
if (x[0] not in d):
d[x[0]] = 0
else:
d[x[0]] += 1
# Out: {'Brasil': 1, 'Italia': 0}
But when i try:
d = {k: (0 if (k not in d) else (d[k]+1)) for k in [x[0] for x in l]}
# Out: {'Brasil': 0, 'Italia': 0}
What an i doing wrong?