treinamentos = [
{'treinamento':'Scrum','moedas':30},
{'treinamento':'Data Science','moedas':40},
{'treinamento':'Gestão de Projetos','moedas':50},
{'treinamento':'Marketing','moedas':30},
{'treinamento':'Cloud','moedas':20},
{'treinamento':'Blockchain','moedas':10},
{'treinamento':'Python','moedas':30}]
pedidos = ['Data Science','Scrum','Gestão de Projetos','Marketing','Cloud','Python','Python','Python',
'Scrum','Data Science','Gestão de Projetos','Marketing','Data Science','Gestão de Projetos',
'Python','Marketing','Data Science','Gestão de Projetos','Data Science','Gestão de Projetos','Data Science']
lista_pedidos = sorted(set(pedidos))
for a in lista_pedidos:
for b in treinamentos:
if a == b['treinamento']:
b['qtde'] = pedidos.count(a)
else:
b['qtde'] = 0
print(treinamentos)Saída:Output:[{'treinamento': 'Scrum', 'moedas': 30, 'qtde': 2}, {'treinamento': 'Data Science', 'moedas': 40, 'qtde': 0}, {'treinamento': 'Gestão de Projetos', 'moedas': 50, 'qtde': 0}, {'treinamento': 'Marketing', 'moedas': 30, 'qtde': 0}, {'treinamento': 'Cloud', 'moedas': 20, 'qtde': 0}, {'treinamento': 'Blockchain', 'moedas': 10, 'qtde': 0}, {'treinamento': 'Python', 'moedas': 30, 'qtde': 0}]
buran write Jun-17-2021, 03:00 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
